[英]Select the count of distinct data
我有此查询,将计算id('id_avocat')出现多少次。 我想选择id仅出现1次的id_avocat;
这是我的查询:
SELECT id_avocat a, COUNT(*) asd ,`planificare` FROM `generare_liste` WHERE `planificare`="instantelor" AND asd <2 GROUP BY a ORDER BY COUNT(*) DESC
我收到此错误: Unknown column 'asd' in 'where clause'
,但是如果仅在select中而不是在where子句中使用“ asd”,则不会出现任何错误。
如何仅选择id Where count(*) is smaller that 2
的ID?
使用HAVING
子句:
SELECT id_avocat, COUNT(*) asd ,`planificare`
FROM `generare_liste`
WHERE `planificare`="instantelor"
GROUP BY a
HAVING COUNT(*) = 1
顺便说一句-您的GROUP BY
a
列a
什么?
让我们根据您的问题假设您的表格结构。
ID_AVOCAT ASD PLANIFICARE A
1 3 instantelor a
2 0 instantelor c
3 1 instantelor b
4 3 instantelor b
6 2 instantelor b
那么您的查询必须像..
SELECT id_avocat,
asd ,
`planificare`
from `GENERARE_LISTE`
group by a
having count(*) < 3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.