Sorting a table in DataView

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!):

  1. 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.
  2. By length(rows) AS "Count", you can re-label the length(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 why SORT length(rows) DESC, not SORT Count DESC.
  3. 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 ..., the SORT command must appear after the GROUP BY line.
2 Likes