Skip to content

Commit 11a1c15

Browse files
authored
Create unpopular-books.sql
1 parent 071ccbb commit 11a1c15

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

MySQL/unpopular-books.sql

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Time: O(m + n)
2+
# Space: O(n)
3+
4+
SELECT b.book_id,
5+
b.NAME
6+
FROM books AS b
7+
LEFT JOIN orders AS o
8+
ON b.book_id = o.book_id
9+
AND dispatch_date BETWEEN '2018-06-23' AND '2019-6-23'
10+
WHERE Datediff('2019-06-23', b.available_from) > 30
11+
GROUP BY book_id
12+
HAVING Sum(IFNULL(o.quantity, 0)) < 10 ORDER BY NULL

0 commit comments

Comments
 (0)