mysql - 查询结果的where子句

标签 mysql sql

我想获取不= 0的金额

我的查询

select c.c_name, sum(cp.invoice_amount)-sum(cp.recived_amount) as amount from customer_payments cp
inner join customer c on c.c_id = cp.customer_id group by c.c_name

从中我得到了所有金额为 0 的客户的结果。

最佳答案

您正在寻找HAVING命令

将其添加到末尾

having amount <> 0

关于mysql - 查询结果的where子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25816316/

相关文章:

使用 IN 而非 INNER JOIN 的 Sql 查询优化

php - 在sql数据库中按年份选择

php - 按类别对项目进行排序

mysql - 有没有人试过将windows上的MySQL数据直接转储到linux上的MySQL?

php - 连接到旧的 MySQL 服务器

SQL,因帕拉 : why can't I do two counts on one query

SQL查询查找表中出现次数最多的值,无需嵌套

mysql - 在 Symfony2 中使用 Doctrine2 和外键

mysql - 在 MySQL 查询中按记录排序并随机混合

SQL 连接多个表