似乎无法让我的专栏以降序显示。
SELECT ROUND(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Employee),2)||" %" AS "% of Employee", R.Region AS Region
FROM Employee R
GROUP BY R.Region
ORDER DESC "% of Employee" DESC
它在DESC中打印出Region的顺序,而不是员工的百分比
% of Employee | Region
-----------------------
3.08% | Darwin
20.64% | Copley
2.44% | Brisbane
2.44% | Albany
答案 0 :(得分:1)
DESC
位于ORDER BY
:
SELECT ROUND(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Employee),2)||" %" AS "% of Employee",
R.Region AS Region
FROM Employee R
GROUP BY R.Region
ORDER BY "% of Employee" DESC
答案 1 :(得分:1)
那是因为您在VARCHAR
上订购了。以降序显示的Regions
只是一个巧合。您需要仅通过COUNT(*)
订购:
SELECT
ROUND(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Employee),2)||" %" AS "% of Employee", R.Region
AS Region
FROM Employee R
GROUP BY R.Region
ORDER BY COUNT(*) DESC