mysql 集合函数与where条件


这里要查询的是去过的国家数(country)的次数ct大于2的人的名字

select name ,count(country) ct from sz03 where ct >2 group by name;

ERROR 1054 (42S22): Unknown column 'ct' in 'where clause'

第一次看到一个和这个类似的sql时,并没有发现这样写是错误的,直到自己也写了一个错误的才想起来。

select name ,ct from (select name ,count(country) ct  from sz03  group by name )as tt  where ct =2;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM