开发者

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

开发者 https://www.devze.com 2022-12-23 22:53 出处:网络
i have a table with coloumn id , name and city 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开发者_StackOverflow query?Yes, it

i have a table with coloumn id , name and city

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开发者_StackOverflow query?


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.

Lets see whether I get that together.

SELECT city, count() from TABLE GROUP BY city HAVING COUNT() >3

Simple beginner SQL

Not sure mysql supports it ;) But it is apart of the standard for ages.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消