userId userName address
1 aa 山东
2 bb 山东
3 cc 山东
4 dd 北京
5 ee 北京
6 ff 河南
7 gg 河南
8 hh 河南
9 kk 上海
要求:查出此表中同一个地址(address)的用户(userName)数量大于2的地址?
select address from tableName group by address having count(userid)>2
select address from (select userId,userName,address from yourTable group by address) t
where (select count(t.username) from t) >2; 试试,
select B from (select count(*) as A,address as B from yourTable group by address) tmpTable where tmpTable.A>2;