0% found this document useful (0 votes)
5 views3 pages

DB Assignment ENONCE

The document outlines a database assignment focused on the Chinook online media store, detailing its structure with 11 tables that include employees, customers, invoices, tracks, albums, artists, genres, and playlists. It provides specific queries to be executed on the database, such as retrieving employee names, artist information, and transaction details, along with hints for expected results. Additionally, it includes a section for transcription where students must describe the output of given SQL queries in English.

Uploaded by

c
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

DB Assignment ENONCE

The document outlines a database assignment focused on the Chinook online media store, detailing its structure with 11 tables that include employees, customers, invoices, tracks, albums, artists, genres, and playlists. It provides specific queries to be executed on the database, such as retrieving employee names, artist information, and transaction details, along with hints for expected results. Additionally, it includes a section for transcription where students must describe the output of given SQL queries in English.

Uploaded by

c
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

computer science — CPES2 Database assignement

1 Introducing the database


In this assignment we will be looking at a database for an online media store called Chinook. The base includes 11 tables
described below. Not all attributes are described, as there are a lot of them (64 in total if i’m not mistaken) and most of them
are self explanatory. the most significant ones are mentioned.
— An e m p l o y e e s table listing informations about the employees of the Chinook company, including their id, title, and the id
of their direct superior if they have one.
— A c u s t o m e r s table listing informations about the customers of the Chinook company, including their id, company, and the
id of their assigned customer service employee.
— An i n v o i c e s table listing the transactions (invoices) recorded by the Chinook company, including the id of the transaction,
the id of the customer, and the total amount of the transaction.
— An i n v o i c e _ i t e m s table listing all the bought tracks, with the id of the track, the id of the transaction, the id of the invoice
item, the price at which the track was bought, and the quantity.
— A t r a c k s table, listing all of the available tracks, including their name, id, the id of the album they’re on, the id of their
genre, their length and size, and their price.
— An a l b u m s table, listing all the albums, with their id, title, and name the id of the artist.
— An a r t i s t s table, listing all the artists, with their name and id.
— A g e n r e table, listing all the genres and their id.
— A d a t a _ t y p e s table, listing all the data types and their id.
— A p l a y l i s t s table, listing all the playlists with their name and id.
— A p l a y l i s t _ t r a c k table, linking the playlists and the tracks with pairs of id.

playlist_track tracks invoice_items invoices


PlaylistId INTEGER TrackId INTEGER InvoiceLineId INTEGER InvoiceId INTEGER
TrackId INTEGER Name STRING InvoiceId INTEGER CustomerId INTEGER
AlbumId INTEGER TrackId INTEGER InvoiceDate DATE

playlists MediaTypeId INTEGER UnitPrice FLOAT BillingAddress STRING


GenreId INTEGER Quantity INTEGER BillingCity STRING
PlaylistId INTEGER
Composer STRING BillingState STRING
Name STRING
Milliseconds INTEGER albums BillingCountry STRING
Bytes INTEGER BillingPostalCode STRING
media_types AlbumId INTEGER
UnitPrice FLOAT Total FLOAT
Title STRING
MediaTypeId INTEGER
ArtistId INTEGER
Name STRING artists
ArtistId INTEGER employees customers
genres Name STRING
EmployeeId INTEGER CustomerId INTEGER
GenreId INTEGER
LastName STRING FirstName STRING
Name STRING
FirstName STRING LastName STRING
Title STRING Company STRING
ReportsTo INTEGER Address STRING
BirthDate DATE City STRING
HireDate DATE State STRING
Address STRING Country STRING

Chinook database City STRING PostalCode STRING

relational diagram State STRING Phone STRING


Country STRING Fax STRING
PostalCode STRING Email STRING
Phone STRING SupportRepId INTEGER
Fax STRING
Email STRING

A word on keys : Primary keys are indicated by underlined attributes. Arrows indicate that the attribute is a foreign key
referring to the pointed to attributed.

Lycée Chateaubriand 1/3


computer science — CPES2 Database assignement

2 Questions
2.1 Queries
1. Write a query returning the first and last names of the employees whose title is ’Sales Support Agent’.
Test. Hint : There are 3 sales support agents.

2. Write a query returning without duplicates the list of artists who performed at least one ’Jazz’ song.
Test. Hint : 10 lines.

3. Write a query returning for each customer their assigned support rep employee. Rename the columns to clearly indicate
which names are the customers names and which names are the employees names.
Test. Hint : 59 lines, only the 3 names from the first query should appear for the employees.

4. Write a query returning the names of tracks that nobody purchased.


Test. Hint : 1369 lines.

5. Write a query returning the minimum and maximum price for a transaction among transaction that included at least
one ’Metal’ track.
Test. Hint : Max is 21.86, min is 0.99.

6. Write a query returning for each sales support agent the number of customers assigned to them.
Test. Hint : Jane has 21, Margaret 20, and Steve 18.

7. Write a query returning the names of the artists who performed at least 10 tracks of more than 5 minutes.
Test. Hint : 17 lines.

8. Write a query returning without duplicates the names of the employees who have at least one other employee reporting
to them.
Test. Hint : There are three : Andrew, Nancy, and Michael.

9. Write a query returning the ’Rock’ tracks that appear on more than 3 playlists.
Test. Hint : 17 lines.

10. Write a query returning the names of the genres having strictly more albums than ’Jazz’.
Test. Hint : 5 lines.

11. Write a query returning the names and total amount of money spent by customers who spent more money than the
average customer.
Test. Hint : 22 lines.

12. Write a query returning the names of customers who bought at least one track of every media type.
Test. Hint : There is only one : Bjørn Hansen.

2.2 Transcription
For each of the following SQL query, write a sentence (in english) describing what it returns, in the same manner as the
questions above.
13.
SELECT DISTINCT customers.FirstName, customers.LastName
FROM customers JOIN invoices ON customers.CustomerId = invoices.CustomerId
JOIN invoice_items ON invoices.InvoiceId = invoice_items.InvoiceId
JOIN tracks ON invoice_items.TrackId = tracks.TrackId
JOIN albums ON tracks.AlbumId = albums.AlbumId
JOIN artists ON albums.ArtistId = artists.ArtistId

Lycée Chateaubriand 2/3


computer science — CPES2 Database assignement

WHERE artists.Name = 'Nirvana'

14.
SELECT artists.Name
FROM artists JOIN albums ON artists.ArtistId = albums.ArtistId
JOIN tracks ON albums.AlbumId = tracks.AlbumId
JOIN invoice_items ON tracks.TrackId = invoice_items.TrackId
GROUP BY artists.ArtistId
HAVING SUM(invoice_items.Quantity) = (SELECT MAX(T)
FROM (SELECT SUM(invoice_items.Quantity) AS T
FROM albums JOIN tracks ON albums.AlbumId = tracks.AlbumId
JOIN invoice_items ON tracks.TrackId = invoice_items.TrackId
GROUP BY albums.ArtistId))

15.
SELECT c.FirstName, c.LastName
FROM customers AS c
WHERE EXISTS (SELECT *
FROM albums AS a
WHERE NOT EXISTS (SELECT *
FROM tracks
WHERE tracks.AlbumId = a.AlbumId
AND tracks.TrackId NOT IN (SELECT ii.TrackId
FROM invoice_items AS ii JOIN invoices AS i
ON ii.InvoiceId = i.InvoiceId
WHERE i.CustomerId = c.CustomerId)))

Lycée Chateaubriand 3/3

You might also like