Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. (SELECT
  2. t1.book_id, books_authors.author_name, t1.amountOfPurchase
  3. FROM
  4. (SELECT
  5. user_books_buy.book_id AS id_book,
  6. COUNT(user_books_buy.book_id) as amountOfPurchase
  7. FROM
  8. user_books_buy
  9. GROUP BY user_books_buy.book_id) AS t1
  10. INNER JOIN
  11. books_authors ON t1.id_book = books_authors.id_book)
  12.  
  13.  
  14. SELECT
  15. t2.authorName,
  16. t2.amountOfPurchase
  17. FROM
  18. (SELECT
  19. books_authors.author_name AS authorName,
  20. MAX(t1.amountOfPurchase) AS amountOfPurchase
  21. FROM
  22. (SELECT
  23. user_books_buy.book_id AS id_book,
  24. COUNT(user_books_buy.book_id) AS amountOfPurchase
  25. FROM
  26. user_books_buy
  27. GROUP BY user_books_buy.book_id) AS t1
  28. INNER JOIN books_authors ON t1.id_book = books_authors.id_book
  29. GROUP BY books_authors.author_name) AS t2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement