Mysql Count(*)为Total WHERE Total?

时间:2010-02-11 16:56:41

标签: sql mysql

SELECT
  Id, QId, UName, Ans, Date, COUNT(*) * 10 as Total
FROM
  question
WHERE
  COUNT(*)
DESC
GROUP BY
  UName

不起作用:(

1 个答案:

答案 0 :(得分:5)

我想你想要过滤群组。使用HAVING COUNT(*)代替WHERE

SELECT Id, QId, UName, Ans, Date, Count(*) * 10 as Total
FROM question
GROUP BY UName
HAVING Count(*)

如果按组件数对组进行排序,请使用ORDER BY

SELECT Id, QId, UName, Ans, Date, Count(*) * 10 as Total
FROM question
GROUP BY UName
ORDER BY Count(*) DESC