简体   繁体   English

sql查询,用于从计数大于3的表中获取不同的记录

[英]sql query for fetching distinct records from table having count greater than 3

i have a table with coloumn id , name and city 我有一张桌子,上面有ID,名字和城市

I want to fetch those rows where city is same and the number of rows are greater than 3. Is it possible in single sql query? 我想获取城市相同且行数大于3的那些行。在单个sql查询中可以吗?

Yes, it is pretty much the level of query I use to filter out the "I know SQL" people that dont have a clue about the language. 是的,这几乎是我用来过滤不了解该语言的“我知道SQL”人员的查询级别。

Lets see whether I get that together. 让我们看看我是否能在一起。

SELECT city, count( ) from TABLE GROUP BY city HAVING COUNT( ) >3 从TABLE GROUP BY的城市中选择城市,count( )的COUNT( )> 3

Simple beginner SQL 简单的初学者SQL

Not sure mysql supports it ;) But it is apart of the standard for ages. 不确定mysql是否支持它;)但是,它是很长时间以来的标准之一。

http://www.w3schools.com/SQL/sql_having.asp http://www.w3schools.com/SQL/sql_having.asp

has more explanations. 有更多的解释。

Yes it is: 是的:

SELECT city, COUNT(id) AS [rowcount]
FROM YourTable
GROUP BY city
HAVING COUNT(id) > 3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM