我有两个表pdc和class
select roll_no as roll,sum(pdc.amount) as amount,count(amount) as given,
stu_profile.name,f_name,scholarship,class_id,batch_id,statuss
from stu_profile left join
pdc
on pdc.roll=stu_profile.roll_no
where 1 and class_id!='' and given=0
group by roll
我想要一个计数(金额)栏的条件
答案 0 :(得分:2)
使用having
子句
. . .
having count(amount) = 0;
答案 1 :(得分:0)
然后回答你的问题是having
条款。但是,您的查询格式错误,无法在大多数数据库中运行,包括更新版本的MySQL。
解决方案很简单:在聚合查询中,SELECT
中的唯一列应该是GROUP BY
密钥或聚合函数的参数。
让我假设你想要:
select p.roll_no as roll, sum(pdc.amount) as amount,
count(pdc.amount) as given,
p.name, p.f_name, p.scholarship, p.class_id, p.batch_id, p.statuss
from stu_profile p left join
pdc
on pdc.roll = p.roll_no
where 1 and class_id <> ''
group by roll, p.name, p.f_name, p.scholarship, p.class_id, p.batch_id, p.statuss
然后你可以添加如下内容:
having given = 0