I have a query similar to:
select *
from combined
where valid_rating is null
order by FIND_IN_SET(provider,
(select provider
from combined
where valid_rating is null group by provider order by count(1) desc)
)
Basically, I am trying to order by the ‘most important’ provider
first (the one with the largest count of items). How would I properly do this with an expression in the order_by
clause, perhaps even using a window function?
2
Answers
Join with the subquery that returns the counts, then order by the counts.
Use
count()
window function, partitioned by provider: