当前位置: 动力学知识库 > 问答 > 编程问答 >

sql - Mysql Count(*) as Total WHERE Total?

问题描述:

SELECT

Id, QId, UName, Ans, Date, COUNT(*) * 10 as Total

FROM

question

WHERE

COUNT(*)

DESC

GROUP BY

UName

doesn't work :(

网友答案:

I think you wanted to filter groups. Use HAVING COUNT(*) instead of WHERE:

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

If you what to sort groups by number of elements then use ORDER BY:

SELECT Id, QId, UName, Ans, Date, Count(*) * 10 as Total
FROM question
GROUP BY UName
ORDER BY Count(*) DESC
分享给朋友:
您可能感兴趣的文章:
随机阅读: