我需要帮助: 这个查询效果很好
main.less
但是当我想过滤
时select count(distinct(a.mat)),count(distinct(c.mail)) as nb
from aca as a
left join c on c.mat=a.mat
group by a.mat
order by nb desc;
我收到此错误
错误1064(42000):您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在第6行的'where nb> 0'附近使用正确的语法
我的查询有什么问题?
答案 0 :(得分:4)
排序依旧应该是最后一次
tapply
答案 1 :(得分:2)
分组函数的条件应该放入HAVING子句:
select count(distinct(a.mat)),count(distinct(c.mail)) as nb
from aca as a
left join c on c.mat=a.mat
group by a.mat
having nb > 0
order by nb desc;