-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_Ex_2.txt
23 lines (23 loc) · 1.39 KB
/
query_Ex_2.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Самый популярный автор при наличии связей «многие ко многим».
SELECT *
FROM authors
WHERE author_id IN (SELECT author_id
FROM m2m_Authors_Books m
JOIN (SELECT b.book_id, count(*) AS count_read
FROM books b
JOIN accounting_of_books a
ON a.book_id = b.book_id
WHERE start_date > (SYSDATE-365)
GROUP BY b.book_id) book_count
ON book_count.book_id = m.book_id
GROUP BY author_id
HAVING SUM(count_read) IN (SELECT MAX(SUM(count_read))
FROM m2m_Authors_Books m
JOIN (SELECT ac.book_id, count(*) AS count_read
FROM accounting_of_books ac
JOIN books b
ON ac.book_id = b.book_id
WHERE start_date > (SYSDATE-365)
GROUP BY ac.book_id) book_count
ON book_count.book_id = m.book_id
GROUP BY author_id));