question
stringlengths
12
244
context
stringlengths
27
489
answer
stringlengths
18
557
List each donator name and the amount of endowment in descending order of the amount of endowment.
CREATE TABLE endowment (donator_name VARCHAR, amount INTEGER)
SELECT donator_name, SUM(amount) FROM endowment GROUP BY donator_name ORDER BY SUM(amount) DESC
List the names of the schools without any endowment.
CREATE TABLE endowment (school_name VARCHAR, school_id VARCHAR); CREATE TABLE school (school_name VARCHAR, school_id VARCHAR)
SELECT school_name FROM school WHERE NOT school_id IN (SELECT school_id FROM endowment)
List all the names of schools with an endowment amount smaller than or equal to 10.
CREATE TABLE school (school_name VARCHAR, school_id VARCHAR); CREATE TABLE endowment (school_id VARCHAR, amount INTEGER)
SELECT T2.school_name FROM endowment AS T1 JOIN school AS T2 ON T1.school_id = T2.school_id GROUP BY T1.school_id HAVING SUM(T1.amount) <= 10
Show the names of donors who donated to both school "Glenn" and "Triton."
CREATE TABLE school (school_id VARCHAR, school_name VARCHAR); CREATE TABLE endowment (donator_name VARCHAR, school_id VARCHAR)
SELECT T1.donator_name FROM endowment AS T1 JOIN school AS T2 ON T1.school_id = T2.school_id WHERE T2.school_name = 'Glenn' INTERSECT SELECT T1.donator_name FROM endowment AS T1 JOIN school AS T2 ON T1.school_id = T2.school_id WHERE T2.school_name = 'Triton'
Show the names of all the donors except those whose donation amount less than 9.
CREATE TABLE endowment (donator_name VARCHAR, amount INTEGER)
SELECT donator_name FROM endowment EXCEPT SELECT donator_name FROM endowment WHERE amount < 9
List the amount and donor name for the largest amount of donation.
CREATE TABLE endowment (amount VARCHAR, donator_name VARCHAR)
SELECT amount, donator_name FROM endowment ORDER BY amount DESC LIMIT 1
How many budgets are above 3000 in year 2001 or before?
CREATE TABLE budget (budgeted VARCHAR, YEAR VARCHAR)
SELECT COUNT(*) FROM budget WHERE budgeted > 3000 AND YEAR <= 2001
Show each school name, its budgeted amount, and invested amount in year 2002 or after.
CREATE TABLE budget (budgeted VARCHAR, invested VARCHAR, school_id VARCHAR, year VARCHAR); CREATE TABLE school (school_name VARCHAR, school_id VARCHAR)
SELECT T2.school_name, T1.budgeted, T1.invested FROM budget AS T1 JOIN school AS T2 ON T1.school_id = T2.school_id WHERE T1.year >= 2002
Show all donor names.
CREATE TABLE endowment (donator_name VARCHAR)
SELECT DISTINCT donator_name FROM endowment
How many budget record has a budget amount smaller than the invested amount?
CREATE TABLE budget (budgeted INTEGER, invested VARCHAR)
SELECT COUNT(*) FROM budget WHERE budgeted < invested
What is the total budget amount for school "Glenn" in all years?
CREATE TABLE budget (budgeted INTEGER, school_id VARCHAR); CREATE TABLE school (school_id VARCHAR, school_name VARCHAR)
SELECT SUM(T1.budgeted) FROM budget AS T1 JOIN school AS T2 ON T1.school_id = T2.school_id WHERE T2.school_name = 'Glenn'
Show the names of schools with a total budget amount greater than 100 or a total endowment greater than 10.
CREATE TABLE endowment (school_id VARCHAR, amount INTEGER); CREATE TABLE budget (school_id VARCHAR, budgeted INTEGER); CREATE TABLE school (school_name VARCHAR, school_id VARCHAR)
SELECT T2.school_name FROM budget AS T1 JOIN school AS T2 ON T1.school_id = T2.school_id JOIN endowment AS T3 ON T2.school_id = T3.school_id GROUP BY T2.school_name HAVING SUM(T1.budgeted) > 100 OR SUM(T3.amount) > 10
Find the names of schools that have more than one donator with donation amount above 8.5.
CREATE TABLE school (School_name VARCHAR, school_id VARCHAR); CREATE TABLE endowment (school_id VARCHAR, amount INTEGER)
SELECT T2.School_name FROM endowment AS T1 JOIN school AS T2 ON T1.school_id = T2.school_id WHERE T1.amount > 8.5 GROUP BY T1.school_id HAVING COUNT(*) > 1
Find the number of schools that have more than one donator whose donation amount is less than 8.5.
CREATE TABLE endowment (school_id VARCHAR, amount INTEGER)
SELECT COUNT(*) FROM (SELECT * FROM endowment WHERE amount > 8.5 GROUP BY school_id HAVING COUNT(*) > 1)
List the name, IHSAA Football Class, and Mascot of the schools that have more than 6000 of budgeted amount or were founded before 2003, in the order of percent of total invested budget and total budgeted budget.
CREATE TABLE school (School_name VARCHAR, Mascot VARCHAR, IHSAA_Football_Class VARCHAR, school_id VARCHAR); CREATE TABLE budget (school_id VARCHAR, total_budget_percent_invested VARCHAR, total_budget_percent_budgeted VARCHAR)
SELECT T1.School_name, T1.Mascot, T1.IHSAA_Football_Class FROM school AS T1 JOIN budget AS T2 ON T1.school_id = T2.school_id WHERE Budgeted > 6000 OR YEAR < 2003 ORDER BY T2.total_budget_percent_invested, T2.total_budget_percent_budgeted
How many buildings are there?
CREATE TABLE building (Id VARCHAR)
SELECT COUNT(*) FROM building
Show the name, street address, and number of floors for all buildings ordered by the number of floors.
CREATE TABLE building (name VARCHAR, street_address VARCHAR, floors VARCHAR)
SELECT name, street_address, floors FROM building ORDER BY floors
What is the name of the tallest building?
CREATE TABLE building (name VARCHAR, height_feet VARCHAR)
SELECT name FROM building ORDER BY height_feet DESC LIMIT 1
What are the average, maximum, and minimum number of floors for all buildings?
CREATE TABLE building (floors INTEGER)
SELECT AVG(floors), MAX(floors), MIN(floors) FROM building
Show the number of buildings with a height above the average or a number of floors above the average.
CREATE TABLE building (height_feet INTEGER, floors INTEGER)
SELECT COUNT(*) FROM building WHERE height_feet > (SELECT AVG(height_feet) FROM building) OR floors > (SELECT AVG(floors) FROM building)
List the names of buildings with at least 200 feet of height and with at least 20 floors.
CREATE TABLE building (name VARCHAR, height_feet VARCHAR, floors VARCHAR)
SELECT name FROM building WHERE height_feet >= 200 AND floors >= 20
Show the names and locations of institutions that are founded after 1990 and have the type "Private".
CREATE TABLE institution (institution VARCHAR, LOCATION VARCHAR, founded VARCHAR, TYPE VARCHAR)
SELECT institution, LOCATION FROM institution WHERE founded > 1990 AND TYPE = 'Private'
Show institution types, along with the number of institutions and total enrollment for each type.
CREATE TABLE institution (TYPE VARCHAR, enrollment INTEGER)
SELECT TYPE, COUNT(*), SUM(enrollment) FROM institution GROUP BY TYPE
Show the institution type with the largest number of institutions.
CREATE TABLE institution (TYPE VARCHAR)
SELECT TYPE FROM institution GROUP BY TYPE ORDER BY COUNT(*) DESC LIMIT 1
Show the institution type with an institution founded after 1990 and an institution with at least 1000 enrollment.
CREATE TABLE institution (TYPE VARCHAR, founded VARCHAR, enrollment VARCHAR)
SELECT TYPE FROM institution WHERE founded > 1990 AND enrollment >= 1000
Show the name of buildings that do not have any institution.
CREATE TABLE building (name VARCHAR, building_id VARCHAR); CREATE TABLE institution (name VARCHAR, building_id VARCHAR)
SELECT name FROM building WHERE NOT building_id IN (SELECT building_id FROM institution)
Show the names of buildings except for those having an institution founded in 2003.
CREATE TABLE building (name VARCHAR, building_id VARCHAR); CREATE TABLE building (name VARCHAR); CREATE TABLE institution (building_id VARCHAR, founded VARCHAR)
SELECT name FROM building EXCEPT SELECT T1.name FROM building AS T1 JOIN institution AS T2 ON T1.building_id = T2.building_id WHERE T2.founded = 2003
For each building, show the name of the building and the number of institutions in it.
CREATE TABLE building (name VARCHAR, building_id VARCHAR); CREATE TABLE institution (building_id VARCHAR)
SELECT T1.name, COUNT(*) FROM building AS T1 JOIN institution AS T2 ON T1.building_id = T2.building_id GROUP BY T1.building_id
Show the names and heights of buildings with at least two institutions founded after 1880.
CREATE TABLE building (name VARCHAR, height_feet VARCHAR, building_id VARCHAR); CREATE TABLE institution (building_id VARCHAR, founded INTEGER)
SELECT T1.name, T1.height_feet FROM building AS T1 JOIN institution AS T2 ON T1.building_id = T2.building_id WHERE T2.founded > 1880 GROUP BY T1.building_id HAVING COUNT(*) >= 2
Show all the distinct institution types.
CREATE TABLE institution (TYPE VARCHAR)
SELECT DISTINCT TYPE FROM institution
Show institution names along with the number of proteins for each institution.
CREATE TABLE institution (institution VARCHAR, institution_id VARCHAR); CREATE TABLE protein (institution_id VARCHAR)
SELECT T1.institution, COUNT(*) FROM institution AS T1 JOIN protein AS T2 ON T1.institution_id = T2.institution_id GROUP BY T1.institution_id
How many proteins are associated with an institution founded after 1880 or an institution with type "Private"?
CREATE TABLE institution (institution_id VARCHAR, founded VARCHAR, type VARCHAR); CREATE TABLE protein (institution_id VARCHAR)
SELECT COUNT(*) FROM institution AS T1 JOIN protein AS T2 ON T1.institution_id = T2.institution_id WHERE T1.founded > 1880 OR T1.type = 'Private'
Show the protein name and the institution name.
CREATE TABLE institution (institution VARCHAR, institution_id VARCHAR); CREATE TABLE protein (protein_name VARCHAR, institution_id VARCHAR)
SELECT T2.protein_name, T1.institution FROM institution AS T1 JOIN protein AS T2 ON T1.institution_id = T2.institution_id
How many proteins are associated with an institution in a building with at least 20 floors?
CREATE TABLE institution (institution_id VARCHAR, building_id VARCHAR); CREATE TABLE building (building_id VARCHAR, floors VARCHAR); CREATE TABLE protein (institution_id VARCHAR)
SELECT COUNT(*) FROM institution AS T1 JOIN protein AS T2 ON T1.institution_id = T2.institution_id JOIN building AS T3 ON T3.building_id = T1.building_id WHERE T3.floors >= 20
How many institutions do not have an associated protein in our record?
CREATE TABLE protein (institution_id VARCHAR); CREATE TABLE institution (institution_id VARCHAR)
SELECT COUNT(*) FROM institution WHERE NOT institution_id IN (SELECT institution_id FROM protein)
Show all the locations where no cinema has capacity over 800.
CREATE TABLE cinema (LOCATION VARCHAR, capacity INTEGER)
SELECT LOCATION FROM cinema EXCEPT SELECT LOCATION FROM cinema WHERE capacity > 800
Show all the locations where some cinemas were opened in both year 2010 and year 2011.
CREATE TABLE cinema (LOCATION VARCHAR, openning_year VARCHAR)
SELECT LOCATION FROM cinema WHERE openning_year = 2010 INTERSECT SELECT LOCATION FROM cinema WHERE openning_year = 2011
How many cinema do we have?
CREATE TABLE cinema (Id VARCHAR)
SELECT COUNT(*) FROM cinema
Show name, opening year, and capacity for each cinema.
CREATE TABLE cinema (name VARCHAR, openning_year VARCHAR, capacity VARCHAR)
SELECT name, openning_year, capacity FROM cinema
Show the cinema name and location for cinemas with capacity above average.
CREATE TABLE cinema (name VARCHAR, LOCATION VARCHAR, capacity INTEGER)
SELECT name, LOCATION FROM cinema WHERE capacity > (SELECT AVG(capacity) FROM cinema)
What are all the locations with a cinema?
CREATE TABLE cinema (LOCATION VARCHAR)
SELECT DISTINCT LOCATION FROM cinema
Show all the cinema names and opening years in descending order of opening year.
CREATE TABLE cinema (name VARCHAR, openning_year VARCHAR)
SELECT name, openning_year FROM cinema ORDER BY openning_year DESC
What are the name and location of the cinema with the largest capacity?
CREATE TABLE cinema (name VARCHAR, LOCATION VARCHAR, capacity VARCHAR)
SELECT name, LOCATION FROM cinema ORDER BY capacity DESC LIMIT 1
Show the average, minimum, and maximum capacity for all the cinemas opened in year 2011 or later.
CREATE TABLE cinema (capacity INTEGER, openning_year VARCHAR)
SELECT AVG(capacity), MIN(capacity), MAX(capacity) FROM cinema WHERE openning_year >= 2011
Show each location and the number of cinemas there.
CREATE TABLE cinema (LOCATION VARCHAR)
SELECT LOCATION, COUNT(*) FROM cinema GROUP BY LOCATION
What is the location with the most cinemas opened in year 2010 or later?
CREATE TABLE cinema (LOCATION VARCHAR, openning_year VARCHAR)
SELECT LOCATION FROM cinema WHERE openning_year >= 2010 GROUP BY LOCATION ORDER BY COUNT(*) DESC LIMIT 1
Show all the locations with at least two cinemas with capacity above 300.
CREATE TABLE cinema (LOCATION VARCHAR, capacity INTEGER)
SELECT LOCATION FROM cinema WHERE capacity > 300 GROUP BY LOCATION HAVING COUNT(*) >= 2
Show the title and director for all films.
CREATE TABLE film (title VARCHAR, directed_by VARCHAR)
SELECT title, directed_by FROM film
Show all directors.
CREATE TABLE film (directed_by VARCHAR)
SELECT DISTINCT directed_by FROM film
List all directors along with the number of films directed by each director.
CREATE TABLE film (directed_by VARCHAR)
SELECT directed_by, COUNT(*) FROM film GROUP BY directed_by
What is total number of show times per dat for each cinema?
CREATE TABLE schedule (show_times_per_day INTEGER, cinema_id VARCHAR); CREATE TABLE cinema (name VARCHAR, cinema_id VARCHAR)
SELECT T2.name, SUM(T1.show_times_per_day) FROM schedule AS T1 JOIN cinema AS T2 ON T1.cinema_id = T2.cinema_id GROUP BY T1.cinema_id
What are the title and maximum price of each film?
CREATE TABLE film (title VARCHAR, film_id VARCHAR); CREATE TABLE schedule (price INTEGER, film_id VARCHAR)
SELECT T2.title, MAX(T1.price) FROM schedule AS T1 JOIN film AS T2 ON T1.film_id = T2.film_id GROUP BY T1.film_id
Show cinema name, film title, date, and price for each record in schedule.
CREATE TABLE schedule (date VARCHAR, price VARCHAR, film_id VARCHAR, cinema_id VARCHAR); CREATE TABLE cinema (name VARCHAR, cinema_id VARCHAR); CREATE TABLE film (title VARCHAR, film_id VARCHAR)
SELECT T3.name, T2.title, T1.date, T1.price FROM schedule AS T1 JOIN film AS T2 ON T1.film_id = T2.film_id JOIN cinema AS T3 ON T1.cinema_id = T3.cinema_id
What are the title and director of the films without any schedule?
CREATE TABLE schedule (title VARCHAR, directed_by VARCHAR, film_id VARCHAR); CREATE TABLE film (title VARCHAR, directed_by VARCHAR, film_id VARCHAR)
SELECT title, directed_by FROM film WHERE NOT film_id IN (SELECT film_id FROM schedule)
Show director with the largest number of show times in total.
CREATE TABLE schedule (film_id VARCHAR, show_times_per_day INTEGER); CREATE TABLE film (directed_by VARCHAR, film_id VARCHAR)
SELECT T2.directed_by FROM schedule AS T1 JOIN film AS T2 ON T1.film_id = T2.film_id GROUP BY T2.directed_by ORDER BY SUM(T1.show_times_per_day) DESC LIMIT 1
Find the locations that have more than one movie theater with capacity above 300.
CREATE TABLE cinema (LOCATION VARCHAR, capacity INTEGER)
SELECT LOCATION FROM cinema WHERE capacity > 300 GROUP BY LOCATION HAVING COUNT(*) > 1
How many films have the word 'Dummy' in their titles?
CREATE TABLE film (title VARCHAR)
SELECT COUNT(*) FROM film WHERE title LIKE "%Dummy%"
Are the customers holding coupons with amount 500 bad or good?
CREATE TABLE discount_coupons (coupon_id VARCHAR, coupon_amount VARCHAR); CREATE TABLE customers (good_or_bad_customer VARCHAR, coupon_id VARCHAR)
SELECT T1.good_or_bad_customer FROM customers AS T1 JOIN discount_coupons AS T2 ON T1.coupon_id = T2.coupon_id WHERE T2.coupon_amount = 500
How many bookings did each customer make? List the customer id, first name, and the count.
CREATE TABLE bookings (customer_id VARCHAR); CREATE TABLE Customers (customer_id VARCHAR, first_name VARCHAR)
SELECT T1.customer_id, T1.first_name, COUNT(*) FROM Customers AS T1 JOIN bookings AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id
What is the maximum total amount paid by a customer? List the customer id and amount.
CREATE TABLE Payments (customer_id VARCHAR, amount_paid INTEGER)
SELECT customer_id, SUM(amount_paid) FROM Payments GROUP BY customer_id ORDER BY SUM(amount_paid) DESC LIMIT 1
What are the id and the amount of refund of the booking that incurred the most times of payments?
CREATE TABLE Payments (booking_id VARCHAR); CREATE TABLE Bookings (booking_id VARCHAR, amount_of_refund VARCHAR)
SELECT T1.booking_id, T1.amount_of_refund FROM Bookings AS T1 JOIN Payments AS T2 ON T1.booking_id = T2.booking_id GROUP BY T1.booking_id ORDER BY COUNT(*) DESC LIMIT 1
What is the id of the product that is booked for 3 times?
CREATE TABLE products_booked (product_id VARCHAR)
SELECT product_id FROM products_booked GROUP BY product_id HAVING COUNT(*) = 3
What is the product description of the product booked with an amount of 102.76?
CREATE TABLE products_for_hire (product_description VARCHAR, product_id VARCHAR); CREATE TABLE products_booked (product_id VARCHAR, booked_amount VARCHAR)
SELECT T2.product_description FROM products_booked AS T1 JOIN products_for_hire AS T2 ON T1.product_id = T2.product_id WHERE T1.booked_amount = 102.76
What are the start date and end date of the booking that has booked the product named 'Book collection A'?
CREATE TABLE bookings (booking_start_date VARCHAR, booking_end_date VARCHAR, booking_id VARCHAR); CREATE TABLE products_booked (product_id VARCHAR, booking_id VARCHAR); CREATE TABLE Products_for_hire (product_id VARCHAR, product_name VARCHAR)
SELECT T3.booking_start_date, T3.booking_end_date FROM Products_for_hire AS T1 JOIN products_booked AS T2 ON T1.product_id = T2.product_id JOIN bookings AS T3 ON T2.booking_id = T3.booking_id WHERE T1.product_name = 'Book collection A'
What are the names of products whose availability equals to 1?
CREATE TABLE view_product_availability (product_id VARCHAR, available_yn VARCHAR); CREATE TABLE products_for_hire (product_name VARCHAR, product_id VARCHAR)
SELECT T2.product_name FROM view_product_availability AS T1 JOIN products_for_hire AS T2 ON T1.product_id = T2.product_id WHERE T1.available_yn = 1
How many different product types are there?
CREATE TABLE products_for_hire (product_type_code VARCHAR)
SELECT COUNT(DISTINCT product_type_code) FROM products_for_hire
What are the first name, last name, and gender of all the good customers? Order by their last name.
CREATE TABLE customers (first_name VARCHAR, last_name VARCHAR, gender_mf VARCHAR, good_or_bad_customer VARCHAR)
SELECT first_name, last_name, gender_mf FROM customers WHERE good_or_bad_customer = 'good' ORDER BY last_name
What is the average amount due for all the payments?
CREATE TABLE payments (amount_due INTEGER)
SELECT AVG(amount_due) FROM payments
What are the maximum, minimum, and average booked count for the products booked?
CREATE TABLE products_booked (booked_count INTEGER)
SELECT MAX(booked_count), MIN(booked_count), AVG(booked_count) FROM products_booked
What are all the distinct payment types?
CREATE TABLE payments (payment_type_code VARCHAR)
SELECT DISTINCT payment_type_code FROM payments
What are the daily hire costs for the products with substring 'Book' in its name?
CREATE TABLE Products_for_hire (daily_hire_cost VARCHAR, product_name VARCHAR)
SELECT daily_hire_cost FROM Products_for_hire WHERE product_name LIKE '%Book%'
How many products are never booked with amount higher than 200?
CREATE TABLE products_booked (product_id VARCHAR, booked_amount INTEGER); CREATE TABLE Products_for_hire (product_id VARCHAR, booked_amount INTEGER)
SELECT COUNT(*) FROM Products_for_hire WHERE NOT product_id IN (SELECT product_id FROM products_booked WHERE booked_amount > 200)
What are the coupon amount of the coupons owned by both good and bad customers?
CREATE TABLE Discount_Coupons (coupon_amount VARCHAR, coupon_id VARCHAR); CREATE TABLE customers (coupon_id VARCHAR, good_or_bad_customer VARCHAR)
SELECT T1.coupon_amount FROM Discount_Coupons AS T1 JOIN customers AS T2 ON T1.coupon_id = T2.coupon_id WHERE T2.good_or_bad_customer = 'good' INTERSECT SELECT T1.coupon_amount FROM Discount_Coupons AS T1 JOIN customers AS T2 ON T1.coupon_id = T2.coupon_id WHERE T2.good_or_bad_customer = 'bad'
What are the payment date of the payment with amount paid higher than 300 or with payment type is 'Check'
CREATE TABLE payments (payment_date VARCHAR, amount_paid VARCHAR, payment_type_code VARCHAR)
SELECT payment_date FROM payments WHERE amount_paid > 300 OR payment_type_code = 'Check'
What are the names and descriptions of the products that are of 'Cutlery' type and have daily hire cost lower than 20?
CREATE TABLE products_for_hire (product_name VARCHAR, product_description VARCHAR, product_type_code VARCHAR, daily_hire_cost VARCHAR)
SELECT product_name, product_description FROM products_for_hire WHERE product_type_code = 'Cutlery' AND daily_hire_cost < 20
How many phones are there?
CREATE TABLE phone (Id VARCHAR)
SELECT COUNT(*) FROM phone
List the names of phones in ascending order of price.
CREATE TABLE phone (Name VARCHAR, Price VARCHAR)
SELECT Name FROM phone ORDER BY Price
What are the memories and carriers of phones?
CREATE TABLE phone (Memory_in_G VARCHAR, Carrier VARCHAR)
SELECT Memory_in_G, Carrier FROM phone
List the distinct carriers of phones with memories bigger than 32.
CREATE TABLE phone (Carrier VARCHAR, Memory_in_G INTEGER)
SELECT DISTINCT Carrier FROM phone WHERE Memory_in_G > 32
Show the names of phones with carrier either "Sprint" or "TMobile".
CREATE TABLE phone (Name VARCHAR, Carrier VARCHAR)
SELECT Name FROM phone WHERE Carrier = "Sprint" OR Carrier = "TMobile"
What is the carrier of the most expensive phone?
CREATE TABLE phone (Carrier VARCHAR, Price VARCHAR)
SELECT Carrier FROM phone ORDER BY Price DESC LIMIT 1
Show different carriers of phones together with the number of phones with each carrier.
CREATE TABLE phone (Carrier VARCHAR)
SELECT Carrier, COUNT(*) FROM phone GROUP BY Carrier
Show the most frequently used carrier of the phones.
CREATE TABLE phone (Carrier VARCHAR)
SELECT Carrier FROM phone GROUP BY Carrier ORDER BY COUNT(*) DESC LIMIT 1
Show the carriers that have both phones with memory smaller than 32 and phones with memory bigger than 64.
CREATE TABLE phone (Carrier VARCHAR, Memory_in_G INTEGER)
SELECT Carrier FROM phone WHERE Memory_in_G < 32 INTERSECT SELECT Carrier FROM phone WHERE Memory_in_G > 64
Show the names of phones and the districts of markets they are on.
CREATE TABLE phone (Name VARCHAR, Phone_ID VARCHAR); CREATE TABLE market (District VARCHAR, Market_ID VARCHAR); CREATE TABLE phone_market (Market_ID VARCHAR, Phone_ID VARCHAR)
SELECT T3.Name, T2.District FROM phone_market AS T1 JOIN market AS T2 ON T1.Market_ID = T2.Market_ID JOIN phone AS T3 ON T1.Phone_ID = T3.Phone_ID
Show the names of phones and the districts of markets they are on, in ascending order of the ranking of the market.
CREATE TABLE market (District VARCHAR, Market_ID VARCHAR, Ranking VARCHAR); CREATE TABLE phone (Name VARCHAR, Phone_ID VARCHAR); CREATE TABLE phone_market (Market_ID VARCHAR, Phone_ID VARCHAR)
SELECT T3.Name, T2.District FROM phone_market AS T1 JOIN market AS T2 ON T1.Market_ID = T2.Market_ID JOIN phone AS T3 ON T1.Phone_ID = T3.Phone_ID ORDER BY T2.Ranking
Show the names of phones that are on market with number of shops greater than 50.
CREATE TABLE market (Market_ID VARCHAR, Num_of_shops INTEGER); CREATE TABLE phone (Name VARCHAR, Phone_ID VARCHAR); CREATE TABLE phone_market (Market_ID VARCHAR, Phone_ID VARCHAR)
SELECT T3.Name FROM phone_market AS T1 JOIN market AS T2 ON T1.Market_ID = T2.Market_ID JOIN phone AS T3 ON T1.Phone_ID = T3.Phone_ID WHERE T2.Num_of_shops > 50
For each phone, show its names and total number of stocks.
CREATE TABLE phone_market (Num_of_stock INTEGER, Phone_ID VARCHAR); CREATE TABLE phone (Name VARCHAR, Phone_ID VARCHAR)
SELECT T2.Name, SUM(T1.Num_of_stock) FROM phone_market AS T1 JOIN phone AS T2 ON T1.Phone_ID = T2.Phone_ID GROUP BY T2.Name
Show the names of phones that have total number of stocks bigger than 2000, in descending order of the total number of stocks.
CREATE TABLE phone_market (Phone_ID VARCHAR, Num_of_stock INTEGER); CREATE TABLE phone (Name VARCHAR, Phone_ID VARCHAR)
SELECT T2.Name FROM phone_market AS T1 JOIN phone AS T2 ON T1.Phone_ID = T2.Phone_ID GROUP BY T2.Name HAVING SUM(T1.Num_of_stock) >= 2000 ORDER BY SUM(T1.Num_of_stock) DESC
List the names of phones that are not on any market.
CREATE TABLE phone (Name VARCHAR, Phone_id VARCHAR, Phone_ID VARCHAR); CREATE TABLE phone_market (Name VARCHAR, Phone_id VARCHAR, Phone_ID VARCHAR)
SELECT Name FROM phone WHERE NOT Phone_id IN (SELECT Phone_ID FROM phone_market)
How many gas companies are there?
CREATE TABLE company (Id VARCHAR)
SELECT COUNT(*) FROM company
List the company name and rank for all companies in the decreasing order of their sales.
CREATE TABLE company (company VARCHAR, rank VARCHAR, Sales_billion VARCHAR)
SELECT company, rank FROM company ORDER BY Sales_billion DESC
Show the company name and the main industry for all companies whose headquarters are not from USA.
CREATE TABLE company (company VARCHAR, main_industry VARCHAR, headquarters VARCHAR)
SELECT company, main_industry FROM company WHERE headquarters <> 'USA'
Show all company names and headquarters in the descending order of market value.
CREATE TABLE company (company VARCHAR, headquarters VARCHAR, market_value VARCHAR)
SELECT company, headquarters FROM company ORDER BY market_value DESC
Show minimum, maximum, and average market value for all companies.
CREATE TABLE company (market_value INTEGER)
SELECT MIN(market_value), MAX(market_value), AVG(market_value) FROM company
Show all main industry for all companies.
CREATE TABLE company (main_industry VARCHAR)
SELECT DISTINCT main_industry FROM company
List all headquarters and the number of companies in each headquarter.
CREATE TABLE company (headquarters VARCHAR)
SELECT headquarters, COUNT(*) FROM company GROUP BY headquarters
Show all main industry and total market value in each industry.
CREATE TABLE company (main_industry VARCHAR, market_value INTEGER)
SELECT main_industry, SUM(market_value) FROM company GROUP BY main_industry
List the main industry with highest total market value and its number of companies.
CREATE TABLE company (main_industry VARCHAR, market_value INTEGER)
SELECT main_industry, COUNT(*) FROM company GROUP BY main_industry ORDER BY SUM(market_value) DESC LIMIT 1
Show headquarters with at least two companies in the banking industry.
CREATE TABLE company (headquarters VARCHAR, main_industry VARCHAR)
SELECT headquarters FROM company WHERE main_industry = 'Banking' GROUP BY headquarters HAVING COUNT(*) >= 2