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;

原文地址:https://www.cnblogs.com/rocky-AGE-24/p/6899026.html