Mixed SQL Challenge: Using INNER JOIN and NOT IN

365 Days of Daily Coding: Day 47

Today was public holiday which I had totally forgotten about so I logged in for my work at around 12 pm and noticed that none of my colleagues were online which was quite strange. I figured out that it might be a glitch or a network lag. I start off my day by viewing my calendar and noticed that it was a “PUBLIC HOLIDAY” today. I wanted to laugh my a*s off at the same time felt unprecendented happiness for getting a day rest.

Today I solved an easy challenge and difficult challenge. The latter challenge did not took me long to solve and so I figured out that I might have advanced from a mere medium level. That needs to be checked cause it’s different working in a real life setting and when working on a challenge like in SQLpad.

Easy Challenge:

SELECT c.name, c.category_id
FROM film_category f JOIN category c
ON f.category_id = c.category_id
GROUP BY c.category_id
ORDER BY COUNT(DISTINCT f.film_id) DESC
LIMIT 1;

Difficult Challenge:

SELECT COUNT(film_id) 
FROM film 
WHERE film_id NOT IN(
  SELECT i.film_id 
  FROM inventory i JOIN rental r
  ON i.inventory_id = r.inventory_id
  WHERE EXTRACT(YEAR FROM rental_ts) = 2020 AND
  EXTRACT(MONTH FROM rental_ts) = 02
  ) ;

Leave a comment