You are on page 1of 4

1.

SELECT BookTitle.Title, BookTitle.Price

FROM BookTitle

WHERE BookTitle.Price < 20;

Explanation: This query will select the title and price of books from the BookTitle table where

the book's price is less than 20.

2.

SELECT BookTitle.Title, Author.AuthorName

FROM Author INNER JOIN BookAuthor ON Author.AuthorID = BookAuthor.AuthorID

INNER JOIN BookTitle ON BookAuthor.ISBN = BookTitle.ISBN

WHERE Author.AuthorName = 'J.K. Rowling';

Explanation: This query will select the title of books written by J.K. Rowling and the author’s

name from the Author, BookAuthor, and BookTitle tables by joining them using their standard

IDs.

3.

SELECT COUNT(CustomerID) as Total_Customers, Country.CountryName

FROM Customer INNER JOIN Country ON Customer.CountryCode = Country.CountryCode

GROUP BY Country.CountryName;
Explanation: This query will count the number of customers from the Customer table for each

country in the Country table and group the results by country name.

4.

SELECT Publisher.PublisherName, AVG(BookTitle.Price) as Average_Price

FROM Publisher INNER JOIN BookTitle ON Publisher.PublisherID = BookTitle.PublisherID

GROUP BY Publisher.PublisherName;

Explanation: This query will select the publisher name from the Publisher table and the average

price of books published by that publisher from the BookTitle table. The results will be grouped

by publisher name.

5.

SELECT BookTitle.Title, Customer.FirstName, Customer.LastName

FROM BookTitle INNER JOIN BookOrder ON BookTitle.ISBN = BookOrder.ISBN

INNER JOIN Customer ON BookOrder.CustomerID = Customer.CustomerID

WHERE Customer.CountryCode = 'US';

Explanation: This query will select the title of books ordered by customers from the US and the

first and last names of those customers from the BookTitle, BookOrder, and Customer tables.
6.

SELECT DISTINCT Category.CategoryName

FROM Category INNER JOIN BookCategory ON Category.CategoryID =

BookCategory.CategoryID;

Explanation: This query will select the distinct category names from the Category table that

have at least one book assigned to them in the BookCategory table.

7.

SELECT Author.AuthorName, COUNT(DISTINCT BookTitle.ISBN) as Total_Books

FROM Author INNER JOIN BookAuthor ON Author.AuthorID = BookAuthor.AuthorID

INNER JOIN BookTitle ON BookAuthor.ISBN = BookTitle.ISBN

GROUP BY Author.AuthorName

HAVING COUNT(DISTINCT BookTitle.ISBN) > 3;

Explanation: By joining them, this query will select the author name and the number of books

they have written from the Author, BookAuthor, and BookTitle tables using their standard IDs.

The results will be grouped by author name and filtered to show only those authors who have

written more than three distinct books.

(2)

The database contains six tables:

 Book: This table contains book information such as the title, ISBN, publication year, price,

and publisher ID.


 Publisher: This table contains information about the published, such as the name, address,

city, state, country, the publisher ID.

 Author: This table contains information about authors, such as the name, address, city, state,

country, the author ID.

 BookAuthor: This table represents the many-to-many relationship between the Book and

Author tables. It contains the ISBN and author ID for each book and author combination.

 Customer: This table contains customer information such as the name, address, city, state,

country, and customer ID.

 Order: This table represents the one-to-many relationship between the Customer and Order

tables. It contains information about customer orders, such as the order ID, order date, and

customer ID.

The relationships between the tables are as follows:

The Book table has a foreign key constraint referencing the Publisher table's primary key to

establish a one-to-many relationship. A single publisher publishes each book.

The BookAuthor table has foreign key constraints referencing the Book and Author tables'

primary keys to establish a many-to-many relationship. Each book can have multiple authors,

and each author can write multiple books.

The Order table has a foreign key constraint referencing the Customer table's primary key to

establish a one-to-many relationship. Each customer can place multiple orders.

The database contains tables representing entities such as books, publishers, authors, customers,

and orders. These tables are related through various relationships, such as one-to-many and

many-to-many.

You might also like