0

我正在尝试根据性别是否为男孩在我的数据库中显示姓名。我目前正在尝试这个查询,但它似乎不起作用。

SELECT
  Name,
  COUNT(Name),
  Gender='Boy' AS totalNumber
FROM
  finaldb
GROUP BY
  Name,
  Gender
ORDER BY
  COUNT(Name) DESC
LIMIT 5

有什么建议么?

4

1 回答 1

1

我认为Gender='Boy'是在错误的地方,把它放在 WHERE 之后

SELECT Name, Gender, COUNT(Name) AS totalNumber FROM finaldb WHERE Gender='Boy' GROUP BY Name, Gender ORDER BY COUNT(Name) DESC LIMIT 5

一般阅读 WHERE 和 SQL 的好地方:

http://www.w3schools.com/sql/sql_where.asp

于 2013-07-16T16:47:35.613 回答