I'm trying to show names in my database based on if the gender is a boy. I'm currently trying this query but it doesn't seem to work.
SELECT
Name,
COUNT(Name),
Gender='Boy' AS totalNumber
FROM
finaldb
GROUP BY
Name,
Gender
ORDER BY
COUNT(Name) DESC
LIMIT 5
Any suggestions?
I think Gender='Boy'
is in the wrong place, put it after WHERE
SELECT Name, Gender, COUNT(Name) AS totalNumber FROM finaldb WHERE Gender='Boy' GROUP BY Name, Gender ORDER BY COUNT(Name) DESC LIMIT 5
A good place to read up on WHERE and SQL in general:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.