Database: store_1

Question: A list of the top 5 countries by number of invoices. List country name and number of invoices.
SQL: SELECT billing_country ,  COUNT(*) FROM invoices GROUP BY billing_country ORDER BY count(*) DESC LIMIT 5;

Question: A list of the top 8 countries by gross/total invoice size. List country name and gross invoice size.
SQL: SELECT billing_country ,  SUM(total) FROM invoices GROUP BY billing_country ORDER BY SUM(total) DESC LIMIT 8;

Question: A list of the top 10 countries by average invoice size. List country name and average invoice size.
SQL: SELECT billing_country ,  AVG(total) FROM invoices GROUP BY billing_country ORDER BY AVG(total) DESC LIMIT 10;

Question: Find out 5 customers who most recently purchased something. List customers' first and last name.
SQL: SELECT T1.first_name ,  T1.last_name FROM customers AS T1 JOIN invoices AS T2 ON T2.customer_id  =  T1.id ORDER BY T2.invoice_date DESC LIMIT 5;

Question: Find out the top 10 customers by total number of orders. List customers' first and last name and the number of total orders.
SQL: SELECT T1.first_name ,  T1.last_name ,  COUNT(*) FROM customers AS T1 JOIN invoices AS T2 ON T2.customer_id  =  T1.id GROUP BY T1.id ORDER BY COUNT(*) DESC LIMIT 10;

Question: List the top 10 customers by total gross sales. List customers' first and last name and total gross sales.
SQL: SELECT T1.first_name ,  T1.last_name ,  SUM(T2.total) FROM customers AS T1 JOIN invoices AS T2 ON T2.customer_id  =  T1.id GROUP BY T1.id ORDER BY SUM(T2.total) DESC LIMIT 10;

Question: List the top 5 genres by number of tracks. List genres name and total tracks.
SQL: SELECT T1.name ,  COUNT(*) FROM genres AS T1 JOIN tracks AS T2 ON T2.genre_id  =  T1.id GROUP BY T1.id ORDER BY count(*) DESC LIMIT 5;

Question: List every album whose title starts with A in alphabetical order.
SQL: SELECT title FROM albums WHERE title LIKE 'A%' ORDER BY title;

Question: List the customers first and last name of 10 least expensive invoices.
SQL: SELECT T1.first_name ,  T1.last_name FROM customers AS T1 JOIN invoices AS T2 ON T2.customer_id  =  T1.id ORDER BY total LIMIT 10;

Question: List total amount of  invoice from Chicago, IL.
SQL: SELECT sum(total) FROM invoices WHERE billing_city  =  "Chicago" AND billing_state  =  "IL";

Question: List the number of invoices from Chicago, IL.
SQL: SELECT COUNT(*) FROM invoices WHERE billing_city  =  "Chicago" AND billing_state  =  "IL";

Question: List the number of invoices from the US, grouped by state.
SQL: SELECT billing_state ,  COUNT(*) FROM invoices WHERE billing_country  =  "USA" GROUP BY billing_state;

Question: List the state in the US with the most invoices.
SQL: SELECT billing_state ,  COUNT(*) FROM invoices WHERE billing_country  =  "USA" GROUP BY billing_state ORDER BY COUNT(*) DESC LIMIT 1;

Question: List the number of invoices and the invoice total from California.
SQL: SELECT billing_state ,  COUNT(*) ,  SUM(total) FROM invoices WHERE billing_state  =  "CA";

Question: List Aerosmith's albums.
SQL: SELECT T1.title FROM albums AS T1 JOIN artists AS T2 ON  T1.artist_id = T2.id WHERE T2.name = "Aerosmith";