Database: gas_company

Question: How many gas companies are there?
SQL: SELECT count(*) FROM company

Question: List the company name and rank for all companies in the decreasing order of their sales.
SQL: SELECT company ,  rank FROM company ORDER BY Sales_billion DESC

Question: Show the company name and the main industry for all companies whose headquarters are not from USA.
SQL: SELECT company ,  main_industry FROM company WHERE headquarters != 'USA'

Question: Show all company names and headquarters in the descending order of market value.
SQL: SELECT company ,  headquarters FROM company ORDER BY market_value DESC

Question: Show minimum, maximum, and average market value for all companies.
SQL: SELECT min(market_value) ,  max(market_value) ,  avg(market_value) FROM company

Question: Show all main industry for all companies.
SQL: SELECT DISTINCT main_industry FROM company

Question: List all headquarters and the number of companies in each headquarter.
SQL: SELECT headquarters ,  count(*) FROM company GROUP BY headquarters

Question: Show all main industry and total market value in each industry.
SQL: SELECT main_industry ,  sum(market_value) FROM company GROUP BY main_industry

Question: List the main industry with highest total market value and its number of companies.
SQL: SELECT main_industry ,  count(*) FROM company GROUP BY main_industry ORDER BY sum(market_value) DESC LIMIT 1

Question: Show headquarters with at least two companies in the banking industry.
SQL: SELECT headquarters FROM company WHERE main_industry  =  'Banking' GROUP BY headquarters HAVING count(*)  >=  2

Question: Show gas station id, location, and manager_name for all gas stations ordered by open year.
SQL: SELECT station_id ,  LOCATION ,  manager_name FROM gas_station ORDER BY open_year

Question: How many gas station are opened between 2000 and 2005?
SQL: SELECT count(*) FROM gas_station WHERE open_year BETWEEN 2000 AND 2005

Question: Show all locations and the number of gas stations in each location ordered by the count.
SQL: SELECT LOCATION ,  count(*) FROM gas_station GROUP BY LOCATION ORDER BY count(*)

Question: Show all headquarters with both a company in banking industry and a company in Oil and gas.
SQL: SELECT headquarters FROM company WHERE main_industry  =  'Banking' INTERSECT SELECT headquarters FROM company WHERE main_industry  =  'Oil and gas'

Question: Show all headquarters without a company in banking industry.
SQL: SELECT headquarters FROM company EXCEPT SELECT headquarters FROM company WHERE main_industry  =  'Banking'

Question: Show the company name with the number of gas station.
SQL: SELECT T2.company ,  count(*) FROM station_company AS T1 JOIN company AS T2 ON T1.company_id  =  T2.company_id GROUP BY T1.company_id

Question: Show company name and main industry without a gas station.
SQL: SELECT company ,  main_industry FROM company WHERE company_id NOT IN (SELECT company_id FROM station_company)