Easy SQL Challenge: Using Subqueries

365 Days of Daily Coding: Day 41

I have to say I was flustered the entire day because of an unexpected event. Therefore, this led me into the recognition of how our minds play the role of our wellbeing. It is not that which could be immediately cured. Emotional resiliency comes with a lot of practice and it is why meditation is emphasised so much for helping to maintain our mental health. If we can tame our mind, we can conquer everything, even the world.

Today, I solved two easy challenges. The second challenge was rather not easy. I would rank it as medium instead.

Easy Challenge 1

SELECT COUNT(customer_id)
FROM customer 
WHERE customer_id NOT IN (SELECT customer_id
						  FROM rental 
						  WHERE EXTRACT(YEAR FROM rental_ts) = 2020
						  AND EXTRACT(MONTH FROM rental_ts) = 05
						  );

Easy Challenge 2

SELECT f.title FROM film f INNER JOIN
(SELECT DISTINCT i.film_id FROM
inventory i INNER JOIN
(SELECT inventory_id FROM rental
WHERE return_ts IS NULL) k
ON i.inventory_id = k.inventory_id) m
ON f.film_id = m.film_id;

Leave a comment