Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
39 changes: 39 additions & 0 deletions your-code/solutions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
USE publications;

-- Challenge 1 - Who Have Published What At Where?

SELECT authors.au_id AS 'Author ID', authors.au_lname AS 'LAST NAME', authors.au_fname AS 'FIRST NAME', titles.title AS 'TITLE', publishers.pub_name AS 'PUBLISHER'
FROM authors
INNER JOIN titleauthor ON authors.au_id = titleauthor.au_id
INNER JOIN titles USING (title_id)
INNER JOIN publishers USING (pub_id);

-- Challenge 2 - Who Have Published How Many At Where?

SELECT authors.au_id AS 'Author ID', authors.au_lname AS 'LAST NAME', authors.au_fname AS 'FIRST NAME', COUNT(titles.title) AS 'TITLE COUNT', publishers.pub_name AS 'PUBLISHER'
FROM authors
INNER JOIN titleauthor ON authors.au_id = titleauthor.au_id
INNER JOIN titles USING (title_id)
INNER JOIN publishers USING (pub_id)
GROUP BY authors.au_id,publishers.pub_name;

-- Challenge 3 - Best Selling Authors

SELECT authors.au_id AS 'Author ID', authors.au_lname AS 'LAST NAME', authors.au_fname AS 'FIRST NAME', SUM(sales.qty) AS 'TOTAL'
FROM authors
INNER JOIN titleauthor ON authors.au_id = titleauthor.au_id
INNER JOIN titles USING (title_id)
INNER JOIN sales USING (title_id)
GROUP BY authors.au_id
ORDER BY TOTAL DESC
LIMIT 3;

-- Challenge 4 - Best Selling Authors Ranking

SELECT authors.au_id AS 'Author ID', authors.au_lname AS 'LAST NAME', authors.au_fname AS 'FIRST NAME', IFNULL(SUM(sales.qty), 0) AS 'TOTAL'
FROM authors
LEFT JOIN titleauthor ON authors.au_id = titleauthor.au_id
LEFT JOIN titles USING (title_id)
LEFT JOIN sales USING (title_id)
GROUP BY authors.au_id
ORDER BY TOTAL DESC;