Try:
TABLE length(rows) AS "Count"
FROM #Article
GROUP BY Source
SORT length(rows) DESC
Here’re some additional explanation based on my current understanding (correct me if I’m saying something wrong!):
- According to the documentation,
rows
contains all of the pages that belong to each group. So you don’t need to append.Source
to get the size of the group. - By
length(rows) AS "Count"
, you can re-label thelength(rows)
column as “Count”. But the scope of this new label “Count” is limited to the first line of the query (if I understand correctly), so you can’t reuse the “Count” label in another line. This is whySORT length(rows) DESC
, notSORT Count DESC
. - A DQL query is executed from top to bottom, line by line. So if you want to sort the groups that you made in the line
GROUP BY ...
, theSORT
command must appear after theGROUP BY
line.