Database: store_product

Question: Find the list of page size which have more than 3 product listed
SQL: SELECT max_page_size FROM product GROUP BY max_page_size HAVING count(*) > 3

Question: Find the name all districts with city area greater than 10 or population larger than 100000
SQL: SELECT district_name FROM district WHERE city_area  >  10 OR City_Population  >  100000

Question: Which district has the largest population?
SQL: SELECT district_name FROM district ORDER BY city_population DESC LIMIT 1

Question: Which district has the least area?
SQL: SELECT district_name FROM district ORDER BY city_area ASC LIMIT 1

Question: Find the names of all stores in Khanewal District.
SQL: SELECT t1.store_name FROM store AS t1 JOIN store_district AS t2 ON t1.store_id  =  t2.store_id JOIN district AS t3 ON t2.district_id  =  t3.district_id WHERE t3.district_name  =  "Khanewal District"

Question: Find all the stores in the district with the most population.
SQL: SELECT t1.store_name FROM store AS t1 JOIN store_district AS t2 ON t1.store_id  =  t2.store_id WHERE district_id  =  (SELECT district_id FROM district ORDER BY city_population DESC LIMIT 1)

Question: Which city is the headquarter of the store named "Blackville" in?
SQL: SELECT t3.headquartered_city FROM store AS t1 JOIN store_district AS t2 ON t1.store_id  =  t2.store_id JOIN district AS t3 ON t2.district_id  =  t3.district_id WHERE t1.store_name  =  "Blackville"

Question: Find the number of stores in each city.
SQL: SELECT t3.headquartered_city ,  count(*) FROM store AS t1 JOIN store_district AS t2 ON t1.store_id  =  t2.store_id JOIN district AS t3 ON t2.district_id  =  t3.district_id GROUP BY t3.headquartered_city

Question: Find the city with the most number of stores.
SQL: SELECT t3.headquartered_city FROM store AS t1 JOIN store_district AS t2 ON t1.store_id  =  t2.store_id JOIN district AS t3 ON t2.district_id  =  t3.district_id GROUP BY t3.headquartered_city ORDER BY count(*) DESC LIMIT 1

Question: What products are available at store named "Miramichi"?
SQL: SELECT t1.product FROM product AS t1 JOIN store_product AS t2 ON t1.product_id  =  t2.product_id JOIN store AS t3 ON t2.store_id  =  t3.store_id WHERE t3.store_name  =  "Miramichi"

Question: Find products with max page size as "A4" and pages per minute color smaller than 5.
SQL: SELECT product FROM product WHERE max_page_size  =  "A4" AND pages_per_minute_color  <  5

Question: Find products with max page size as "A4" or pages per minute color smaller than 5.
SQL: SELECT product FROM product WHERE max_page_size  =  "A4" OR pages_per_minute_color  <  5

Question: Find all the product whose name contains the word "Scanner".
SQL: SELECT product FROM product WHERE product LIKE "%Scanner%"

Question: Find the most prominent max page size among all the products.
SQL: SELECT max_page_size FROM product GROUP BY max_page_size ORDER BY count(*) DESC LIMIT 1

Question: Find the name of the products that are not using the most frequently-used max page size.
SQL: SELECT product FROM product WHERE max_page_size != (SELECT max_page_size FROM product GROUP BY max_page_size ORDER BY count(*) DESC LIMIT 1)