From a570800f76e56a64c799f28ecc19bf79788ee0ae Mon Sep 17 00:00:00 2001 From: LuciaGPalos <113399853+LuciaGPalos@users.noreply.github.com> Date: Mon, 31 Oct 2022 01:35:46 -0600 Subject: [PATCH 1/3] Lucia mysql select --- .DS_Store | Bin 0 -> 6148 bytes solutions.sql | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 .DS_Store create mode 100644 solutions.sql diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..4b067cb414cab8bdb14cd2a64024282791890c88 GIT binary patch literal 6148 zcmeHKyH3ME5S)b+K?so!$}5o&mO@KoBB!9Bfgd0b1V|?4mEOO@SDM+|17zd02%+6* zZ}#qX?#?6S9sp#rUXFngfFWH`H0UvH?(N!2$pfOqF-qKGg*%ofJp=v4CSChJ7P!X@ zC4b-RA0xw)e$7Q$E#_r4XQs+@Mn7tzG1|mF-N1hDuy=5UDb7*gl9=HU%l3S7&|&Q1 z6%|*y#v2|Otys_K&nP?07c!4+rA@=w%@uG3Tme_W6;K6uW~&W%4ZU;)Tme_$O99;< z0$njrSR2NzgGGD-5cL`zjj>*ml@k)?32Q_4(8Q=jqe^;Wh|$>|QeK|0HZ(dUJw7DO z{P}p1I6KD=F&&Z{dg%(d0&NAhtvb^4f6Bj1?<2oW@tP~(3j8w#WKdie6Mj@WTYr3> xp0$B~Ls!$hS_2y6)+K-y-A4{%r}YPonU^Q54RsW4k94A61fn2bxB|bRzz2rrNSFWs literal 0 HcmV?d00001 diff --git a/solutions.sql b/solutions.sql new file mode 100644 index 0000000..a8ca710 --- /dev/null +++ b/solutions.sql @@ -0,0 +1,74 @@ +##Challenge 1 - Who Have Published What At Where? +SELECT a.au_id AS 'AUTHOR ID', +a.au_lname AS 'LAST NAME', +a.au_fname AS 'FIRST NAME', +t.title AS 'TITLE', +p.pub_name AS 'PUBLISHER' +FROM authors a +JOIN titleauthor ta +ON a.au_id = ta.au_id +JOIN titles t +ON ta.title_id = t.title_id +JOIN publishers p +ON t.pub_id = p.pub_id; + +##Challenge 2 - Who Have Published How Many At Where? +SELECT a.au_id AS 'AUTHOR ID', +a.au_lname AS 'LAST NAME', +a.au_fname AS 'FIRST NAME', +p.pub_name AS 'PUBLISHER', +COUNT(t.title) AS 'TITLE COUNT' +FROM authors a +JOIN titleauthor ta +ON a.au_id = ta.au_id +JOIN titles t +ON ta.title_id = t.title_id +JOIN publishers p +ON t.pub_id = p.pub_id +GROUP BY title; + +##Challenge 3 - Best Selling Authors +SELECT a.au_id AS 'AUTHOR ID', +a.au_lname AS 'LAST NAME', +a.au_fname AS 'FIRST NAME', +SUM(s.qty) AS 'TOTAL' +FROM authors a +JOIN titleauthor ta +ON a.au_id = ta.au_id +JOIN sales s +ON s.title_id = ta.title_id +GROUP BY a.au_id +ORDER BY TOTAL DESC +LIMIT 3; + +##Challenge 4 - Best Selling Authors Ranking +UPDATE sales +SET qty = 0 +WHERE qty IS NULL; + +##unsure how to solve challenge 4... +SELECT a.au_id AS 'AUTHOR ID', +a.au_lname AS 'LAST NAME', +a.au_fname AS 'FIRST NAME', +COALESCE(SUM(s.qty),0) AS 'TOTAL' +FROM authors a +JOIN titleauthor ta +ON a.au_id = ta.au_id +JOIN sales s +ON s.title_id = ta.title_id +GROUP BY a.au_id +ORDER BY TOTAL DESC; + +##Bonus 4 - Most Profiting Authors +SELECT a.au_id AS 'AUTHOR ID', +a.au_lname AS 'LAST NAME', +a.au_fname AS 'FIRST NAME', +SUM(t.advance + ta.royaltyper) AS 'PROFIT' +FROM authors a +JOIN titleauthor ta +ON a.au_id = ta.au_id +JOIN titles t +ON ta.title_id = t.title_id +GROUP BY a.au_id +ORDER BY PROFIT DESC +LIMIT 3; \ No newline at end of file From 215acdc2891d9bbf759e9d997798186c881e127c Mon Sep 17 00:00:00 2001 From: LuciaGPalos <113399853+LuciaGPalos@users.noreply.github.com> Date: Mon, 31 Oct 2022 21:48:09 -0600 Subject: [PATCH 2/3] Lucia Updated Solution Corrected challenge 4 --- .DS_Store | Bin 6148 -> 6148 bytes solutions.sql | 11 +++-------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.DS_Store b/.DS_Store index 4b067cb414cab8bdb14cd2a64024282791890c88..c7fbc141cea8d4ff31066903ca8e4193733dd3a9 100644 GIT binary patch delta 23 ecmZoMXffFEoRPJafq_9|^E*aKw#}>@|M>x1$Ol3I delta 25 hcmZoMXffFEoRPhVfq_B$|NqTz7$w;@vvd6A2LO2y2`~Tv diff --git a/solutions.sql b/solutions.sql index a8ca710..4c4c0eb 100644 --- a/solutions.sql +++ b/solutions.sql @@ -42,19 +42,14 @@ ORDER BY TOTAL DESC LIMIT 3; ##Challenge 4 - Best Selling Authors Ranking -UPDATE sales -SET qty = 0 -WHERE qty IS NULL; - -##unsure how to solve challenge 4... SELECT a.au_id AS 'AUTHOR ID', a.au_lname AS 'LAST NAME', a.au_fname AS 'FIRST NAME', -COALESCE(SUM(s.qty),0) AS 'TOTAL' +SUM(s.qty) AS 'TOTAL' FROM authors a -JOIN titleauthor ta +LEFT JOIN titleauthor ta ON a.au_id = ta.au_id -JOIN sales s +LEFT JOIN sales s ON s.title_id = ta.title_id GROUP BY a.au_id ORDER BY TOTAL DESC; From 803c8e6ad59471268c753a09513f4cb06640c03e Mon Sep 17 00:00:00 2001 From: LuciaGPalos <113399853+LuciaGPalos@users.noreply.github.com> Date: Mon, 31 Oct 2022 21:59:34 -0600 Subject: [PATCH 3/3] Challenge 4 Lu --- solutions.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions.sql b/solutions.sql index 4c4c0eb..1e57c30 100644 --- a/solutions.sql +++ b/solutions.sql @@ -45,7 +45,7 @@ LIMIT 3; SELECT a.au_id AS 'AUTHOR ID', a.au_lname AS 'LAST NAME', a.au_fname AS 'FIRST NAME', -SUM(s.qty) AS 'TOTAL' +SUM(IFNULL(s.qty,0)) AS 'TOTAL' FROM authors a LEFT JOIN titleauthor ta ON a.au_id = ta.au_id