365 Days of Coding: Day 34
Lately, my health has not been good. I have been feeling severe neck and shoulder pain for the past few days. It might be the result of lack of exercise which I am having a tough time to incorporate into my daily routine. I am not a morning person so I stay up late most of the days. I have few colleagues that are in Eastern Time zone which makes it a 7 hour difference. The only overlapping times are from 4pm to 6.30pm Malaysian time which is normally my preferred time for exercise. Well, this may be an excuse. If I wanted to exercise, I would and can find the time.
For today’s challenge, I solved an easy challenge in sqlpad.io. I struggled a bit cause I was accidentally pressing to go back to a previous page while typing in my query. When I returned to the editor, my queries would be no more. Anyway, today I had to find the category that had the highest no. of items, and return the category_id as well as the count of items in the category.
I used GROUP BY to group the rows by category, ORDER BY to order the groups in DESC order and LIMIT 1 to return only the first row which is the category with the highest items. I think I could have used RANK() and OVER() to also return the expected results.
I am happy that despite not feeling well, I have committed to my daily post today.

Leave a comment