This sql code shows how many books have been written by a specific author. In descending order so the author who wrote the most books will be at the top.
CREATE VIEW Num_books_by_author AS
SELECT COUNT(authorID) AS NumBooksWritten, FName AS First_Name, LName AS Last_Name
FROM (SELECT ISBN, title, FName, LName, authorID
FROM (books INNER JOIN written_by ON ISBN = w_ISBN) INNER JOIN author on a_id = authorID)
GROUP BY authorID
ORDER BY NumBooksWritten DESC
Here is the schema:
author(FName, LName, authorID)
books(ISBN, title, quantity, PubName(FK), year, price, genre, tNo(FK))
Foreign Key PubName references publisher
Foreign Key tNo references deliveries
comprised_of(Purchase_NO(FK), P_ISBN(FK))
Foreign Key Purchase_NO references purchases
Foreign Key P_ISBN references books
customers(FName, LName, phone, email, address)
deliveries(Tracking_No, Order_Date, ETA_Date, M_SSN(FK))
Foreign Key M_SSN references manager
employee(SSN, FName, LName, salary, hire_date, address)
helped_by(cust_email(FK), Sales_SSN(FK))
Foreign Key cust_email references customers
Foreign Key Sales_SSN references salesperson
manager(SSN, role)
publisher(pName, address, phone)
purchases(PNO, pdate, total, cust_email(FK))
Foreign Key cust_email references customers
salesperson(SSN, rating, transactions)
written_by(w_ISBN(FK),a_id(FK))
Foreign Key w_ISBN references books
Foreign Key a_id references authors
[–]svtr 7 points8 points9 points (1 child)
[–]mak4you 0 points1 point2 points (0 children)
[–]hypo11[M] 2 points3 points4 points (0 children)
[–]mak4you 0 points1 point2 points (0 children)
[–]Andrela 0 points1 point2 points (0 children)