From bb4918e180ebeda76c41981f16a47f9ad9d2a8a1 Mon Sep 17 00:00:00 2001 From: Berna Ozer Date: Wed, 22 Nov 2023 14:41:07 +0100 Subject: [PATCH] Berna Ozer --- .DS_Store | Bin 0 -> 6148 bytes your-code/solutions.sql | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 .DS_Store create mode 100644 your-code/solutions.sql diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..585f2e55d09f2fd16dfede08624ce10c7610cd60 GIT binary patch literal 6148 zcmeHK!AiqG5S?wSX(&Pu3OxqAR;(rH!Apqs2aM=Jr6wlSV45vSYLQaNS%1hc@q3)v z-HNsKDr$FN_RY@DB+SdQn*jjkj>7|hCIHk?2`eTJD}>fbm!zURHAE(!5kVeI@==iR zU@2NVej@|)?KUBXA^0$W#qakTjFLDnI-NIGsn#|&4Z}1V#*KH+Ctl$f~ropx=zZFRf$ ztZhw?$hHsd+03l(?Cu|*^&gU9%AX~X4ELOnEroMGz(D`7Y5;_V?iQ?$M zL9_sf^cyJzZR#Z`$5QAhEG6O!3X`dbGL@+ogUNLCTPn^`SW1-Xz*O_W)SH>=P?&f- zKHn1Iz#NHs)C_0_78$6@X_M~%)9?HL#Uwq`3}^=a6$7l+^Lj3pr0&+G;^?lmP;XI5 pD6W+Fk%ES}iZPb1;ufk9^jl;gItojP=t0px0)hrTXa;_ifp-J^i{bzP literal 0 HcmV?d00001 diff --git a/your-code/solutions.sql b/your-code/solutions.sql new file mode 100644 index 0000000..73017dc --- /dev/null +++ b/your-code/solutions.sql @@ -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;