Solved

sql mysql count

Posted on 2008-06-11
2
289 Views
Last Modified: 2010-03-19
SELECT COUNT(*) AS `Rows`, `Ssurname` FROM `member` GROUP BY `Ssurname` Where Rows > 2
ORDER BY `Rows` Desc


 MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Where Rows > 2
ORDER BY `Rows` Desc
LIMIT 0, 30' at line 1


How can icorrect the code above
0
Comment
Question by:teera
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 250 total points
ID: 21757859
Conditions for the grouping are named having like:

 SELECT COUNT(*) AS `Rows`, `Ssurname` FROM `member` GROUP BY `Ssurname` HAVING COUNT(*) > 2
0
 
LVL 6

Assisted Solution

by:dragos_craciun
dragos_craciun earned 250 total points
ID: 21757865
You must write

SELECT COUNT(*) AS `Rows`, `Ssurname` FROM `member` GROUP BY `Ssurname`
HAVING COUNT(*) > 2
ORDER BY `Rows` Desc

WHERE can be used only for individual rows
For filtering on aggregates, use HAVING
0

Featured Post

AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question