diff --git a/publications(SOLUTION).sqbpro b/publications(SOLUTION).sqbpro new file mode 100644 index 0000000..8c38d27 --- /dev/null +++ b/publications(SOLUTION).sqbpro @@ -0,0 +1,50 @@ +
SELECT + authors.au_id AS "AUTHOR ID", + authors.au_lname AS "LAST NAME", + authors.au_fname AS "FIRST NAME", + titles.title AS "TITLE", + COALESCE(publishers.pub_name, 'Unknown') AS "PUBLISHER" +FROM authors +JOIN titleauthor ON authors.au_id = titleauthor.au_id +JOIN titles ON titleauthor.title_id = titles.title_id +LEFT JOIN publishers ON titles.pub_id = publishers.pub_id; + +SELECT + authors.au_id AS "AUTHOR ID", + authors.au_lname AS "LAST NAME", + authors.au_fname AS "FIRST NAME", + COALESCE(publishers.pub_name, 'Unknown') AS "PUBLISHER", + COUNT(titles.title) AS "TITLE COUNT" +FROM authors +JOIN titleauthor ON authors.au_id = titleauthor.au_id +JOIN titles ON titleauthor.title_id = titles.title_id +LEFT JOIN publishers ON titles.pub_id = publishers.pub_id +GROUP BY authors.au_id, publishers.pub_name +ORDER BY "TITLE COUNT" DESC; + +SELECT + authors.au_id AS "AUTHOR ID", + authors.au_lname AS "LAST NAME", + authors.au_fname AS "FIRST NAME", + COALESCE(SUM(sales.qty), 0) AS "TOTAL" +FROM authors +JOIN titleauthor ON authors.au_id = titleauthor.au_id +JOIN titles ON titleauthor.title_id = titles.title_id +LEFT JOIN sales ON titles.title_id = sales.title_id +GROUP BY authors.au_id +ORDER BY "TOTAL" DESC +LIMIT 3; + +SELECT + authors.au_id AS "AUTHOR ID", + authors.au_lname AS "LAST NAME", + authors.au_fname AS "FIRST NAME", + COALESCE(SUM(sales.qty), 0) AS "TOTAL" +FROM authors +LEFT JOIN titleauthor ON authors.au_id = titleauthor.au_id +LEFT JOIN titles ON titleauthor.title_id = titles.title_id +LEFT JOIN sales ON titles.title_id = sales.title_id +GROUP BY authors.au_id, authors.au_lname, authors.au_fname +HAVING COALESCE(SUM(sales.qty), 0) = 0 +ORDER BY "TOTAL" DESC; +