-
Notifications
You must be signed in to change notification settings - Fork 0
/
SQL Project 1.sql
26 lines (20 loc) · 1.15 KB
/
SQL Project 1.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
show databases
use project_1
SELECT * FROM employee
/* Q1: Which countries have the most Invoices? */
SELECT COUNT(*) AS c, billing_country FROM invoice GROUP BY billing_country ORDER BY c DESC;
/* Q2: Return all the track names that have a song length longer than the average song length.
Return the Name and Milliseconds for each track. Order by the song length with the longest songs listed first. */
SELECT name,milliseconds FROM track
WHERE milliseconds > (
SELECT AVG(milliseconds) AS avg_track_length
FROM track )
ORDER BY milliseconds DESC;
/* Q3: Which city has the best customers? We would like to throw a promotional Music Festival in the city we made the most money.
Write a query that returns one city that has the highest sum of invoice totals.
Return both the city name & sum of all invoice totals */
SELECT billing_city,SUM(total) AS InvoiceTotal FROM invoice GROUP BY billing_city ORDER BY InvoiceTotal DESC LIMIT 1;
/* Q4: What are top 3 values of total invoice? */
SELECT total FROM invoice ORDER BY total DESC LIMIT 3;
/* Q5: What are top 3 billing cities of total invoice? */
SELECT billing_city,total FROM invoice ORDER BY total DESC LIMIT 3;