Question: Write the following questions as queries in SQL. Use only the operators discussed in class in particular, no outer joins. Type and format your answers.
Write the following questions as queries in SQL. Use only the operators discussed in class in particular, no outer joins. Type and format your answers. Before starting, make sure you understand the schema of the database. If you are in doubt about it, please ask the instructor. Assume a database with schema
AUTHOR(name,age,address,nationality)
BOOK(title,year,genre,price,num-pages,publisher)
WRITES(aname,btitle,royalty)
where the table AUTHOR contains information about writers, and name is the primary key; BOOK contains information about books (their title, the year they were published, their price, the number of pages and the name of the publisher who published it1 ) and title is the primary key. Attribute genre is one of humor, biography, sci-fi, horror and so on. WRITES tells us which author has written which book(s) (so aname and btitle are foreign keys in WRITES) 2 , and what percentage of the book price they got in royalties.3 Note that an author may have written several books, and a book may have been written by several authors jointly; the key of WRITES is (aname,btitle). Write the following questions in SQL:
a) Find the titles of the most expensive book of 2020.
b)Find the number of books published by each publisher during the 2010s (between 2010 and 2020). List only publishers with at least 5 books.
c) Find the titles and authors of the books that have more pages than the average number of pages for a book (in the whole database).
d)The take of an author on a book is the product of the authors royalties times the price of the book. The profit of an author is the sum of the takes on all his/her books. Give the 10 most profitable authors in the database (you can break ties arbitrarily).
e)List the number of books per author, counting only books with a single author (equivalently, authors who have authored the book alone). NOTE: if an author has authored 2 books alone, and 3 with other people, only the 2 written alone count
Discussed in class ( SLECT, FROM, WHERE, GROUP, AGGREGATE FUNCTIONS, HAVING, SUB-GROUPIING, INTERSECT, UNION)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
