CASE Study DBMS - 1
CASE Study DBMS - 1
CASE Study DBMS - 1
Scenario: You are managing a database for an art gallery that tracks artists, artworks, exhibitions, and sales.
Tables:
• Artists (ArtistID, Name, BirthYear,
Nationality)
• Artworks (ArtworkID, Title, ArtistID, YearCreated, Price)
• Exhibitions (ExhibitionID, Title, StartDate, EndDate)
• Sales (SaleID, ArtworkID, ExhibitionID, SaleDate, SalePrice)
Questions:
2. Alter sales table and add one more column of your own choice
3. Insert sample data into each table (at least 5 records per table).
-- Insert data into Artists
INSERT INTO Artists (ArtistID, Name, BirthYear, Nationality)
VALUES
(1, 'Pablo Picasso', 1881, 'Spanish'),
(2, 'Vincent van Gogh', 1853, 'Dutch'),
(3, 'Frida Kahlo', 1907, 'Mexican'),
(4, 'Salvador Dalí', 1904, 'Spanish'),
(5, 'Claude Monet', 1840, 'French');
8. Find the ExhibitionID where the total sales amount is the highest.
SELECT ExhibitionID
FROM Sales
GROUP BY ExhibitionID
ORDER BY SUM(SalePrice) DESC
LIMIT 1;
9. List the names of all artists and the titles of their artworks.
SELECT Artists.Name, Artworks.Title
FROM Artists
JOIN Artworks ON Artists.ArtistID = Artworks.ArtistID;
10. Retrieve the titles and sale prices of artworks sold during exhibitions starting in 2024.
SELECT Artworks.Title, Sales.SalePrice
FROM Sales
JOIN Exhibitions ON Sales.ExhibitionID = Exhibitions.ExhibitionID
JOIN Artworks ON Sales.ArtworkID = Artworks.ArtworkID
WHERE Exhibitions.StartDate >= '2024-01-01';
12. Display exhibitions and their total sales, including those with no sales.
SELECT Exhibitions.Title, SUM(Sales.SalePrice) AS TotalSales
FROM Exhibitions
LEFT JOIN Sales ON Exhibitions.ExhibitionID = Sales.ExhibitionID
GROUP BY Exhibitions.Title;
13. Find artists who have artworks both exhibited and sold (use INTERSECT).
SELECT ArtistID
FROM Artworks
WHERE ArtworkID IN (SELECT ArtworkID FROM Sales)
INTERSECT
SELECT ArtistID
FROM Artworks
WHERE ArtworkID IN (SELECT ArtworkID FROM Exhibitions);
14. List all unique exhibition titles and artwork titles combined (use UNION).
15. Combine the table Artist and Artworks through ArtistID (use JOIN)