100% found this document useful (1 vote)
5K views3 pages

Practice Exercise On Chinook Part-1 Solution

Uploaded by

Prerna Shetty
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
100% found this document useful (1 vote)
5K views3 pages

Practice Exercise On Chinook Part-1 Solution

Uploaded by

Prerna Shetty
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

Practice exercise on chinook

Using the chinook database, write SQLite queries to answer the following
questions in DB Browser.

Q.1 What is the title of the album with AlbumId 67?

select Title
from albums
where AlbumId=67;

Q.2 Find the name and length (in seconds) of all tracks that have length
between 50 and 70 seconds.

select name, Milliseconds/1000 as seconds


from tracks
where seconds BETWEEN 50 AND 70

Q.3 List all the albums by artists with the word ‘black’ in their name.

select name
from artists
where name like "%black%"

Q.4 Provide a query showing a unique/distinct list of billing countries from the
Invoice table
SELECT DISTINCT BillingCountry
FROM invoices;

Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
Q.5 Display the city with highest sum total invoice.
SELECT BillingCity, round(sum(Total),2) as TotalInvoice
FROM invoices
group by BillingCity
ORDER by TotalInvoice DESC
limit 1;

Q.6 Produce a table that lists each country and the number of customers in
that country. (You only need to include countries that have customers) in
descending order. (Highest count at the top)

select country, count(CustomerId) as counts


from customers
group by Country
having counts > 0
order by counts desc;

Q.7 Find the top five customers in terms of sales i.e. find the five customers
whose total combined invoice amounts are the highest. Give their name,
CustomerId and total invoice amount. Use join

select FirstName, i.CustomerId, sum(total) as total_sum


from invoices i inner join customers c on c.CustomerId=i.CustomerId
group by i.CustomerId
order by total_sum desc
limit 5;

Q.8 Find out state wise count of customerID and list the names of states with
count of customerID in decreasing order. Note:- do not include where states is
null value.

Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.
select state, count( CustomerId) as counts
from customers
where state IS NOT NULL
group by State
order by counts desc;

Q.9 How many Invoices were there in 2009 and 2011?

SELECT COUNT(InvoiceId) as "Total Invoices"


FROM Invoices
WHERE InvoiceDate between "2009-01-01" AND "2011-01-01";

Q.10 Provide a query showing only the Employees who are Sales Agents.

SELECT FirstName||" "||LastName as "Sales Employee"


FROM employees
WHERE Title LIKE "Sales%";

Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited.

You might also like