在sql中降序

时间:2016-05-17 02:20:26

标签: sql sqlite

似乎无法让我的专栏以降序显示。

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

2 个答案:

答案 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