【发布时间】:2015-02-13 16:44:59
【问题描述】:
其实我现在有一张桌子:
[Person Table]:
ID Name age City
====================================
1 Jack 14 New York
2 Mike 15 LA
3 Ben 16 Beijing
?
100 Lee 32 Singapore
(total record = 100)
(Id is Primary Key)
请提供SQL脚本来查询客户他/她的城市在表中出现大于等于6个。
例子:
The number of customer that live in New York is 10
The number of customer that live in LA=5
The number of customer that live in Beijing=6.
因此,在此示例中,输出应该是所有居住在纽约和北京的客户。
【问题讨论】:
-
使用
COUNT(*)和GROUP BY获取每个城市的人数。 -
到目前为止,您是否尝试过任何查询?
-
我试过了,但可能有问题。 select * from Person where (select count(*) from Person group by City)>6