This repository has been archived on 2025-07-20. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
fsad/assignment4/query.sql
AKP 4903fd730e
Assignment 4
Signed-off-by: AKP <tom@tdpain.net>
2023-04-29 18:12:46 +01:00

15 lines
816 B
SQL

-- get library id
select libraryid from "library" where city = 'Alexandria';
-- get author id
select authorid from author where familyname = 'Tolkien';
-- get all books by the author
select * from book where authorid = (select authorid from author where familyname = 'Tolkien');
-- get all available copies of the books from the above author in the above library
select book.title, book.publisher, book.genre, book.rrp, count(*) as "number_available" from bookcopy join book on bookcopy.bookid = book.bookid where
libraryid = (select libraryid from "library" where city = 'Alexandria') and
bookcopy.bookid in (select bookid from book where authorid = (select authorid from author where familyname = 'Tolkien')) and
(onloan = false or onloan is null)
group by book.title, book.publisher, book.genre, book.rrp;