Skip to content

Commit 3544e01

Browse files
authored
Update Unpopular Books.sql
1 parent c251f94 commit 3544e01

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Medium/Unpopular Books.sql

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,22 @@ having sum(case when year(dispatch_date) = 2018 then 1 else 0 end) < 10
114114

115115

116116

117-
117+
Prac:
118+
with books as (
119+
select book_id, name
120+
from Books
121+
where datediff(day, available_from, '2019-06-23') > 30
122+
), orders as (
123+
select book_id, sum(quantity) as tot
124+
from orders
125+
where year(dispatch_date) = 2018
126+
group by book_id
127+
), agg as (
128+
select book_id, name, coalesce(tot, 0)
129+
from books b left join orders o on b.book_id = o.book_id
130+
)
131+
select book_id, name
132+
from agg
133+
where tot <= 10
118134

119135

0 commit comments

Comments
 (0)