Dbms Assignment-1 Baarth
Dbms Assignment-1 Baarth
Dbms Assignment-1 Baarth
917722IT012
Creating a Database:
CREATE DATABASE Bookstore;
Creating Tables:
CREATE TABLE Authors (
AuthorID INT PRIMARY KEY,
AuthorName VARCHAR(100),
Country VARCHAR(50)
);
Complex Queries:
1) Find authors with more than 3 books:
SELECT Authors.AuthorName, COUNT(Books.BookID) AS
NumberOfBooks
FROM Authors
JOIN Books ON Authors.AuthorID = Books.AuthorID
GROUP BY Authors.AuthorID
HAVING COUNT(Books.BookID) > 3;
4) List all books and their authors for a specific year (e.g., 2010):
SELECT Books.Title, Authors.AuthorName
FROM Books
JOIN Authors ON Books.AuthorID = Authors.AuthorID
WHERE Books.YearPublished = 2010;
5) Find the average price of books for each author and only display authors
who have published more than one book.
SELECT a.AuthorName, COUNT(b.BookID) AS NumberOfBooks,
AVG(b.Price) AS AveragePrice
FROM Authors a
JOIN Books b ON a.AuthorID = b.AuthorID
GROUP BY a.AuthorName
HAVING COUNT(b.BookID) > 1;