Skip to content
Advertisement

Order by the Compute of Count in SQL

Hi I get the results that I’m looking for however, I want to order it by the count from the compute. Anyone have any ideas.

enter image description here

Advertisement

Answer

One approach is to use window functions to calculate and order by that value.

The following orders the result by n descending, but doesn’t include n in the final SELECT list.

I kept your original order criteria to break any ties.

Example result:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement