Write SQL query to sort based on 2 columns | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

Write SQL query to sort based on 2 columns

I have to write query in Oracle to sort the result based on count descending and then by manufacturer in ascending order. I tried many ways to write this but I'm getting errors. If anyone can guide me that would be a great help

20th May 2021, 2:54 PM
Pinky
2 ответов
+ 1
If you sort by 2 parameters one after the other, it gives the same result as sorting by only the last parameter.
20th May 2021, 3:09 PM
Ore
Ore - avatar
+ 1
Given that you are (correctly) counting and grouping in the same query, you just have to ORDER BY COUNT(column_name) DESC, manufacturer ASC. Note that the ASC clause is not mandatory and can be omitted but in this case gives more readability. 😎
5th Feb 2022, 7:38 AM
Giacomo Montali