We are in Beta and we are offering 50% off! Use code BETATESTER at checkout.
You can access a significantly larger sample of the platform's content for free by logging in with your Gmail account. Sign in now to explore.

Songs that did not enter the charts or entered high

SQL Medium

Assume the following schema:

Calculate the number of songs that either did not make the charts or entered the charts and had a max rank greater than 90. The result should look like the following:

Number of songs
4845
There are several ways to answer this question, perhaps the easiest one is to use a left join and then filter on NULL as follows:

SELECT  count(*) as 'Number of songs'
FROM songs t1 LEFT JOIN charts t2
ON t1.trackid = t2.trackid
where maxRank is Null or maxRank > 90;
Number of songs
4845

Alternatively, we can use a subquery:

SELECT  count(*) as 'Number of songs'
FROM songs t1 
WHERE t1.trackid NOT IN 
(SELECT DISTINCT trackid FROM charts WHERE maxRank <= 90)
Number of songs
4845
Topics

Subquery, Join
Similar questions

Provide feedback