365 Days of Daily Coding: Day 32
I had a gairly good start of a weekend. In the morning, I had a very nice chat with my family who are currently living in Kathmandu. It’s been 2 years since I last went back home. As you all may know because of the pandemic traveling is not easy as it was previously.
It was right before the pandemic started when we were supposed to go on a family vacation. It was not yet bad as it is right now. But things were still uncertain and we didn’t want to take the risk especially for both my mom and dad. I bet a lot of you have plans to travel once this whole pandemic is over. I wonder if there will come a time when this pandemic is all over. What if this thing is here to stay and this our new normal.
As for today’s challenge, I had to categorise the actors by the first letter of their names. If their name began with “A” then they would be under category “a_actors”, likewise for “B”, it would be “b_actors”; for “C”, it would be “c_actors” and for other letters, it would be “other_actors”
Table: actor
| actor_id | integer |
| first_name | text |
| last_name | text |
Expected Solution:
| actor_category | count |
|---|---|
| a_actors | 123 |
| b_actors | 78 |
My Solution:
SELECT
CASE
WHEN UPPER(first_name) LIKE 'A%'
THEN 'a_actors'
WHEN UPPER(first_name) LIKE 'B%'
THEN 'b_actors'
WHEN UPPER(first_name) LIKE 'C%'
THEN 'c_actors'
ELSE
'other_actors'
END actor_category,
count(*)
FROM actor
GROUP BY actor_category;

Leave a comment