db_id
stringclasses
146 values
question
stringlengths
3
224
sql
stringlengths
18
577
database_schema
stringclasses
146 values
school_finance
How many budgets are above 3000 in year 2001 or before?
SELECT count(*) FROM budget WHERE budgeted > 3000 AND YEAR <= 2001
CREATE TABLE "School" ( "School_id" text, "School_name" text, "Location" text, "Mascot" text, "Enrollment" int, "IHSAA_Class" text, "IHSAA_Football_Class" text, "County" text, PRIMARY KEY ("School_id") ) 3 rows from School table: School_id School_name Location Mascot Enrollment IHSAA_Class IHSAA_Football_Class County 1 Bremen Bremen Lions 495 AA AA 50 Marshall 2 Culver Community Culver Cavaliers 287 A A 50 Marshall 3 Glenn Walkerton Falcons 605 AAA AAA 71 St. Joseph CREATE TABLE "budget" ( "School_id" int, "Year" int, "Budgeted" int, "total_budget_percent_budgeted" real, "Invested" int, "total_budget_percent_invested" real, "Budget_invested_percent" text, PRIMARY KEY("School_id","YEAR"), FOREIGN KEY("School_id") REFERENCES "School"("School_id") ) 3 rows from budget table: School_id Year Budgeted total_budget_percent_budgeted Invested total_budget_percent_invested Budget_invested_percent 2 1999 4979 2.0 2134 2.0 42.9 2 2000 3666 2.0 5840 2.0 159.3 2 2001 6803 2.0 8335 2.0 122.5 CREATE TABLE "endowment" ( "endowment_id" int, "School_id" int, "donator_name" text, "amount" real, PRIMARY KEY("endowment_id"), FOREIGN KEY("School_id") REFERENCES "School"("School_id") ) 3 rows from endowment table: endowment_id School_id donator_name amount 1 1 Monte Plata 9.51 2 2 San José de Ocoa 9.83 3 3 Distrito Nacional 9.55
school_finance
Count the number of budgets in year 2001 or before whose budgeted amount is greater than 3000
SELECT count(*) FROM budget WHERE budgeted > 3000 AND YEAR <= 2001
CREATE TABLE "School" ( "School_id" text, "School_name" text, "Location" text, "Mascot" text, "Enrollment" int, "IHSAA_Class" text, "IHSAA_Football_Class" text, "County" text, PRIMARY KEY ("School_id") ) 3 rows from School table: School_id School_name Location Mascot Enrollment IHSAA_Class IHSAA_Football_Class County 1 Bremen Bremen Lions 495 AA AA 50 Marshall 2 Culver Community Culver Cavaliers 287 A A 50 Marshall 3 Glenn Walkerton Falcons 605 AAA AAA 71 St. Joseph CREATE TABLE "budget" ( "School_id" int, "Year" int, "Budgeted" int, "total_budget_percent_budgeted" real, "Invested" int, "total_budget_percent_invested" real, "Budget_invested_percent" text, PRIMARY KEY("School_id","YEAR"), FOREIGN KEY("School_id") REFERENCES "School"("School_id") ) 3 rows from budget table: School_id Year Budgeted total_budget_percent_budgeted Invested total_budget_percent_invested Budget_invested_percent 2 1999 4979 2.0 2134 2.0 42.9 2 2000 3666 2.0 5840 2.0 159.3 2 2001 6803 2.0 8335 2.0 122.5 CREATE TABLE "endowment" ( "endowment_id" int, "School_id" int, "donator_name" text, "amount" real, PRIMARY KEY("endowment_id"), FOREIGN KEY("School_id") REFERENCES "School"("School_id") ) 3 rows from endowment table: endowment_id School_id donator_name amount 1 1 Monte Plata 9.51 2 2 San José de Ocoa 9.83 3 3 Distrito Nacional 9.55
school_finance
Show each school name, its budgeted amount, and invested amount in year 2002 or after.
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
CREATE TABLE "School" ( "School_id" text, "School_name" text, "Location" text, "Mascot" text, "Enrollment" int, "IHSAA_Class" text, "IHSAA_Football_Class" text, "County" text, PRIMARY KEY ("School_id") ) 3 rows from School table: School_id School_name Location Mascot Enrollment IHSAA_Class IHSAA_Football_Class County 1 Bremen Bremen Lions 495 AA AA 50 Marshall 2 Culver Community Culver Cavaliers 287 A A 50 Marshall 3 Glenn Walkerton Falcons 605 AAA AAA 71 St. Joseph CREATE TABLE "budget" ( "School_id" int, "Year" int, "Budgeted" int, "total_budget_percent_budgeted" real, "Invested" int, "total_budget_percent_invested" real, "Budget_invested_percent" text, PRIMARY KEY("School_id","YEAR"), FOREIGN KEY("School_id") REFERENCES "School"("School_id") ) 3 rows from budget table: School_id Year Budgeted total_budget_percent_budgeted Invested total_budget_percent_invested Budget_invested_percent 2 1999 4979 2.0 2134 2.0 42.9 2 2000 3666 2.0 5840 2.0 159.3 2 2001 6803 2.0 8335 2.0 122.5 CREATE TABLE "endowment" ( "endowment_id" int, "School_id" int, "donator_name" text, "amount" real, PRIMARY KEY("endowment_id"), FOREIGN KEY("School_id") REFERENCES "School"("School_id") ) 3 rows from endowment table: endowment_id School_id donator_name amount 1 1 Monte Plata 9.51 2 2 San José de Ocoa 9.83 3 3 Distrito Nacional 9.55
school_finance
Show all donor names.
SELECT DISTINCT donator_name FROM endowment
CREATE TABLE "School" ( "School_id" text, "School_name" text, "Location" text, "Mascot" text, "Enrollment" int, "IHSAA_Class" text, "IHSAA_Football_Class" text, "County" text, PRIMARY KEY ("School_id") ) 3 rows from School table: School_id School_name Location Mascot Enrollment IHSAA_Class IHSAA_Football_Class County 1 Bremen Bremen Lions 495 AA AA 50 Marshall 2 Culver Community Culver Cavaliers 287 A A 50 Marshall 3 Glenn Walkerton Falcons 605 AAA AAA 71 St. Joseph CREATE TABLE "budget" ( "School_id" int, "Year" int, "Budgeted" int, "total_budget_percent_budgeted" real, "Invested" int, "total_budget_percent_invested" real, "Budget_invested_percent" text, PRIMARY KEY("School_id","YEAR"), FOREIGN KEY("School_id") REFERENCES "School"("School_id") ) 3 rows from budget table: School_id Year Budgeted total_budget_percent_budgeted Invested total_budget_percent_invested Budget_invested_percent 2 1999 4979 2.0 2134 2.0 42.9 2 2000 3666 2.0 5840 2.0 159.3 2 2001 6803 2.0 8335 2.0 122.5 CREATE TABLE "endowment" ( "endowment_id" int, "School_id" int, "donator_name" text, "amount" real, PRIMARY KEY("endowment_id"), FOREIGN KEY("School_id") REFERENCES "School"("School_id") ) 3 rows from endowment table: endowment_id School_id donator_name amount 1 1 Monte Plata 9.51 2 2 San José de Ocoa 9.83 3 3 Distrito Nacional 9.55
school_finance
How many budget record has a budget amount smaller than the invested amount?
SELECT count(*) FROM budget WHERE budgeted < invested
CREATE TABLE "School" ( "School_id" text, "School_name" text, "Location" text, "Mascot" text, "Enrollment" int, "IHSAA_Class" text, "IHSAA_Football_Class" text, "County" text, PRIMARY KEY ("School_id") ) 3 rows from School table: School_id School_name Location Mascot Enrollment IHSAA_Class IHSAA_Football_Class County 1 Bremen Bremen Lions 495 AA AA 50 Marshall 2 Culver Community Culver Cavaliers 287 A A 50 Marshall 3 Glenn Walkerton Falcons 605 AAA AAA 71 St. Joseph CREATE TABLE "budget" ( "School_id" int, "Year" int, "Budgeted" int, "total_budget_percent_budgeted" real, "Invested" int, "total_budget_percent_invested" real, "Budget_invested_percent" text, PRIMARY KEY("School_id","YEAR"), FOREIGN KEY("School_id") REFERENCES "School"("School_id") ) 3 rows from budget table: School_id Year Budgeted total_budget_percent_budgeted Invested total_budget_percent_invested Budget_invested_percent 2 1999 4979 2.0 2134 2.0 42.9 2 2000 3666 2.0 5840 2.0 159.3 2 2001 6803 2.0 8335 2.0 122.5 CREATE TABLE "endowment" ( "endowment_id" int, "School_id" int, "donator_name" text, "amount" real, PRIMARY KEY("endowment_id"), FOREIGN KEY("School_id") REFERENCES "School"("School_id") ) 3 rows from endowment table: endowment_id School_id donator_name amount 1 1 Monte Plata 9.51 2 2 San José de Ocoa 9.83 3 3 Distrito Nacional 9.55
school_finance
What is the total budget amount for school "Glenn" in all years?
SELECT sum(T1.budgeted) FROM budget AS T1 JOIN school AS T2 ON T1.school_id = T2.school_id WHERE T2.school_name = 'Glenn'
CREATE TABLE "School" ( "School_id" text, "School_name" text, "Location" text, "Mascot" text, "Enrollment" int, "IHSAA_Class" text, "IHSAA_Football_Class" text, "County" text, PRIMARY KEY ("School_id") ) 3 rows from School table: School_id School_name Location Mascot Enrollment IHSAA_Class IHSAA_Football_Class County 1 Bremen Bremen Lions 495 AA AA 50 Marshall 2 Culver Community Culver Cavaliers 287 A A 50 Marshall 3 Glenn Walkerton Falcons 605 AAA AAA 71 St. Joseph CREATE TABLE "budget" ( "School_id" int, "Year" int, "Budgeted" int, "total_budget_percent_budgeted" real, "Invested" int, "total_budget_percent_invested" real, "Budget_invested_percent" text, PRIMARY KEY("School_id","YEAR"), FOREIGN KEY("School_id") REFERENCES "School"("School_id") ) 3 rows from budget table: School_id Year Budgeted total_budget_percent_budgeted Invested total_budget_percent_invested Budget_invested_percent 2 1999 4979 2.0 2134 2.0 42.9 2 2000 3666 2.0 5840 2.0 159.3 2 2001 6803 2.0 8335 2.0 122.5 CREATE TABLE "endowment" ( "endowment_id" int, "School_id" int, "donator_name" text, "amount" real, PRIMARY KEY("endowment_id"), FOREIGN KEY("School_id") REFERENCES "School"("School_id") ) 3 rows from endowment table: endowment_id School_id donator_name amount 1 1 Monte Plata 9.51 2 2 San José de Ocoa 9.83 3 3 Distrito Nacional 9.55
school_finance
Show the names of schools with a total budget amount greater than 100 or a total endowment greater than 10.
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
CREATE TABLE "School" ( "School_id" text, "School_name" text, "Location" text, "Mascot" text, "Enrollment" int, "IHSAA_Class" text, "IHSAA_Football_Class" text, "County" text, PRIMARY KEY ("School_id") ) 3 rows from School table: School_id School_name Location Mascot Enrollment IHSAA_Class IHSAA_Football_Class County 1 Bremen Bremen Lions 495 AA AA 50 Marshall 2 Culver Community Culver Cavaliers 287 A A 50 Marshall 3 Glenn Walkerton Falcons 605 AAA AAA 71 St. Joseph CREATE TABLE "budget" ( "School_id" int, "Year" int, "Budgeted" int, "total_budget_percent_budgeted" real, "Invested" int, "total_budget_percent_invested" real, "Budget_invested_percent" text, PRIMARY KEY("School_id","YEAR"), FOREIGN KEY("School_id") REFERENCES "School"("School_id") ) 3 rows from budget table: School_id Year Budgeted total_budget_percent_budgeted Invested total_budget_percent_invested Budget_invested_percent 2 1999 4979 2.0 2134 2.0 42.9 2 2000 3666 2.0 5840 2.0 159.3 2 2001 6803 2.0 8335 2.0 122.5 CREATE TABLE "endowment" ( "endowment_id" int, "School_id" int, "donator_name" text, "amount" real, PRIMARY KEY("endowment_id"), FOREIGN KEY("School_id") REFERENCES "School"("School_id") ) 3 rows from endowment table: endowment_id School_id donator_name amount 1 1 Monte Plata 9.51 2 2 San José de Ocoa 9.83 3 3 Distrito Nacional 9.55
school_finance
Find the names of schools that have more than one donator with donation amount above 8.5.
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
CREATE TABLE "School" ( "School_id" text, "School_name" text, "Location" text, "Mascot" text, "Enrollment" int, "IHSAA_Class" text, "IHSAA_Football_Class" text, "County" text, PRIMARY KEY ("School_id") ) 3 rows from School table: School_id School_name Location Mascot Enrollment IHSAA_Class IHSAA_Football_Class County 1 Bremen Bremen Lions 495 AA AA 50 Marshall 2 Culver Community Culver Cavaliers 287 A A 50 Marshall 3 Glenn Walkerton Falcons 605 AAA AAA 71 St. Joseph CREATE TABLE "budget" ( "School_id" int, "Year" int, "Budgeted" int, "total_budget_percent_budgeted" real, "Invested" int, "total_budget_percent_invested" real, "Budget_invested_percent" text, PRIMARY KEY("School_id","YEAR"), FOREIGN KEY("School_id") REFERENCES "School"("School_id") ) 3 rows from budget table: School_id Year Budgeted total_budget_percent_budgeted Invested total_budget_percent_invested Budget_invested_percent 2 1999 4979 2.0 2134 2.0 42.9 2 2000 3666 2.0 5840 2.0 159.3 2 2001 6803 2.0 8335 2.0 122.5 CREATE TABLE "endowment" ( "endowment_id" int, "School_id" int, "donator_name" text, "amount" real, PRIMARY KEY("endowment_id"), FOREIGN KEY("School_id") REFERENCES "School"("School_id") ) 3 rows from endowment table: endowment_id School_id donator_name amount 1 1 Monte Plata 9.51 2 2 San José de Ocoa 9.83 3 3 Distrito Nacional 9.55
school_finance
Find the number of schools that have more than one donator whose donation amount is less than 8.5.
SELECT count(*) FROM (SELECT * FROM endowment WHERE amount > 8.5 GROUP BY school_id HAVING count(*) > 1)
CREATE TABLE "School" ( "School_id" text, "School_name" text, "Location" text, "Mascot" text, "Enrollment" int, "IHSAA_Class" text, "IHSAA_Football_Class" text, "County" text, PRIMARY KEY ("School_id") ) 3 rows from School table: School_id School_name Location Mascot Enrollment IHSAA_Class IHSAA_Football_Class County 1 Bremen Bremen Lions 495 AA AA 50 Marshall 2 Culver Community Culver Cavaliers 287 A A 50 Marshall 3 Glenn Walkerton Falcons 605 AAA AAA 71 St. Joseph CREATE TABLE "budget" ( "School_id" int, "Year" int, "Budgeted" int, "total_budget_percent_budgeted" real, "Invested" int, "total_budget_percent_invested" real, "Budget_invested_percent" text, PRIMARY KEY("School_id","YEAR"), FOREIGN KEY("School_id") REFERENCES "School"("School_id") ) 3 rows from budget table: School_id Year Budgeted total_budget_percent_budgeted Invested total_budget_percent_invested Budget_invested_percent 2 1999 4979 2.0 2134 2.0 42.9 2 2000 3666 2.0 5840 2.0 159.3 2 2001 6803 2.0 8335 2.0 122.5 CREATE TABLE "endowment" ( "endowment_id" int, "School_id" int, "donator_name" text, "amount" real, PRIMARY KEY("endowment_id"), FOREIGN KEY("School_id") REFERENCES "School"("School_id") ) 3 rows from endowment table: endowment_id School_id donator_name amount 1 1 Monte Plata 9.51 2 2 San José de Ocoa 9.83 3 3 Distrito Nacional 9.55
school_finance
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.
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
CREATE TABLE "School" ( "School_id" text, "School_name" text, "Location" text, "Mascot" text, "Enrollment" int, "IHSAA_Class" text, "IHSAA_Football_Class" text, "County" text, PRIMARY KEY ("School_id") ) 3 rows from School table: School_id School_name Location Mascot Enrollment IHSAA_Class IHSAA_Football_Class County 1 Bremen Bremen Lions 495 AA AA 50 Marshall 2 Culver Community Culver Cavaliers 287 A A 50 Marshall 3 Glenn Walkerton Falcons 605 AAA AAA 71 St. Joseph CREATE TABLE "budget" ( "School_id" int, "Year" int, "Budgeted" int, "total_budget_percent_budgeted" real, "Invested" int, "total_budget_percent_invested" real, "Budget_invested_percent" text, PRIMARY KEY("School_id","YEAR"), FOREIGN KEY("School_id") REFERENCES "School"("School_id") ) 3 rows from budget table: School_id Year Budgeted total_budget_percent_budgeted Invested total_budget_percent_invested Budget_invested_percent 2 1999 4979 2.0 2134 2.0 42.9 2 2000 3666 2.0 5840 2.0 159.3 2 2001 6803 2.0 8335 2.0 122.5 CREATE TABLE "endowment" ( "endowment_id" int, "School_id" int, "donator_name" text, "amount" real, PRIMARY KEY("endowment_id"), FOREIGN KEY("School_id") REFERENCES "School"("School_id") ) 3 rows from endowment table: endowment_id School_id donator_name amount 1 1 Monte Plata 9.51 2 2 San José de Ocoa 9.83 3 3 Distrito Nacional 9.55
protein_institute
How many buildings are there?
SELECT count(*) FROM building
CREATE TABLE "building" ( "building_id" text, "Name" text, "Street_address" text, "Years_as_tallest" text, "Height_feet" int, "Floors" int, PRIMARY KEY("building_id") ) 3 rows from building table: building_id Name Street_address Years_as_tallest Height_feet Floors 0 Citizens Bank Building 701 North Franklin Street 1913–1915 145 12 1 Tampa City Hall 315 John F. Kennedy Boulevard 1915–1926 160 10 2 Floridan Hotel 905 Franklin Street 1926–1966 204 17 CREATE TABLE "Institution" ( "Institution_id" text, "Institution" text, "Location" text, "Founded" real, "Type" text, "Enrollment" int, "Team" text, "Primary_Conference" text, "building_id" text, PRIMARY KEY("Institution_id"), FOREIGN KEY ("building_id") REFERENCES "building"("building_id") ) 3 rows from Institution table: Institution_id Institution Location Founded Type Enrollment Team Primary_Conference building_id 0 Ave Maria University Ave Maria, Florida 1998.0 Private 1200 Gyrenes The Sun 1 1 Dakota State University Madison, South Dakota 1881.0 Public 3102 Trojans none 1 2 Edward Waters College Jacksonville, Florida 1866.0 Private 800 Tigers Gulf Coast (GCAC) 3 CREATE TABLE "protein" ( "common_name" text, "protein_name" text, "divergence_from_human_lineage" real, "accession_number" text, "sequence_length" real, "sequence_identity_to_human_protein" text, "Institution_id" text, PRIMARY KEY("common_name"), FOREIGN KEY("Institution_id") REFERENCES "Institution"("Institution_id") ) 3 rows from protein table: common_name protein_name divergence_from_human_lineage accession_number sequence_length sequence_identity_to_human_protein Institution_id Tropical Clawed Frog uncharacterized protein C20orf117-like 371.2 XP_002942331.1 1584.0 39% 1 purple sea urchin uncharacterized protein LOC578090 742.9 XP_783370.2 1587.0 47% 3 body louse Centromeric protein E, putative 782.7 XP_002429877.1 2086.0 30% 5
protein_institute
Show the name, street address, and number of floors for all buildings ordered by the number of floors.
SELECT name , street_address , floors FROM building ORDER BY floors
CREATE TABLE "building" ( "building_id" text, "Name" text, "Street_address" text, "Years_as_tallest" text, "Height_feet" int, "Floors" int, PRIMARY KEY("building_id") ) 3 rows from building table: building_id Name Street_address Years_as_tallest Height_feet Floors 0 Citizens Bank Building 701 North Franklin Street 1913–1915 145 12 1 Tampa City Hall 315 John F. Kennedy Boulevard 1915–1926 160 10 2 Floridan Hotel 905 Franklin Street 1926–1966 204 17 CREATE TABLE "Institution" ( "Institution_id" text, "Institution" text, "Location" text, "Founded" real, "Type" text, "Enrollment" int, "Team" text, "Primary_Conference" text, "building_id" text, PRIMARY KEY("Institution_id"), FOREIGN KEY ("building_id") REFERENCES "building"("building_id") ) 3 rows from Institution table: Institution_id Institution Location Founded Type Enrollment Team Primary_Conference building_id 0 Ave Maria University Ave Maria, Florida 1998.0 Private 1200 Gyrenes The Sun 1 1 Dakota State University Madison, South Dakota 1881.0 Public 3102 Trojans none 1 2 Edward Waters College Jacksonville, Florida 1866.0 Private 800 Tigers Gulf Coast (GCAC) 3 CREATE TABLE "protein" ( "common_name" text, "protein_name" text, "divergence_from_human_lineage" real, "accession_number" text, "sequence_length" real, "sequence_identity_to_human_protein" text, "Institution_id" text, PRIMARY KEY("common_name"), FOREIGN KEY("Institution_id") REFERENCES "Institution"("Institution_id") ) 3 rows from protein table: common_name protein_name divergence_from_human_lineage accession_number sequence_length sequence_identity_to_human_protein Institution_id Tropical Clawed Frog uncharacterized protein C20orf117-like 371.2 XP_002942331.1 1584.0 39% 1 purple sea urchin uncharacterized protein LOC578090 742.9 XP_783370.2 1587.0 47% 3 body louse Centromeric protein E, putative 782.7 XP_002429877.1 2086.0 30% 5
protein_institute
What is the name of the tallest building?
SELECT name FROM building ORDER BY height_feet DESC LIMIT 1
CREATE TABLE "building" ( "building_id" text, "Name" text, "Street_address" text, "Years_as_tallest" text, "Height_feet" int, "Floors" int, PRIMARY KEY("building_id") ) 3 rows from building table: building_id Name Street_address Years_as_tallest Height_feet Floors 0 Citizens Bank Building 701 North Franklin Street 1913–1915 145 12 1 Tampa City Hall 315 John F. Kennedy Boulevard 1915–1926 160 10 2 Floridan Hotel 905 Franklin Street 1926–1966 204 17 CREATE TABLE "Institution" ( "Institution_id" text, "Institution" text, "Location" text, "Founded" real, "Type" text, "Enrollment" int, "Team" text, "Primary_Conference" text, "building_id" text, PRIMARY KEY("Institution_id"), FOREIGN KEY ("building_id") REFERENCES "building"("building_id") ) 3 rows from Institution table: Institution_id Institution Location Founded Type Enrollment Team Primary_Conference building_id 0 Ave Maria University Ave Maria, Florida 1998.0 Private 1200 Gyrenes The Sun 1 1 Dakota State University Madison, South Dakota 1881.0 Public 3102 Trojans none 1 2 Edward Waters College Jacksonville, Florida 1866.0 Private 800 Tigers Gulf Coast (GCAC) 3 CREATE TABLE "protein" ( "common_name" text, "protein_name" text, "divergence_from_human_lineage" real, "accession_number" text, "sequence_length" real, "sequence_identity_to_human_protein" text, "Institution_id" text, PRIMARY KEY("common_name"), FOREIGN KEY("Institution_id") REFERENCES "Institution"("Institution_id") ) 3 rows from protein table: common_name protein_name divergence_from_human_lineage accession_number sequence_length sequence_identity_to_human_protein Institution_id Tropical Clawed Frog uncharacterized protein C20orf117-like 371.2 XP_002942331.1 1584.0 39% 1 purple sea urchin uncharacterized protein LOC578090 742.9 XP_783370.2 1587.0 47% 3 body louse Centromeric protein E, putative 782.7 XP_002429877.1 2086.0 30% 5
protein_institute
What are the average, maximum, and minimum number of floors for all buildings?
SELECT avg(floors) , max(floors) , min(floors) FROM building
CREATE TABLE "building" ( "building_id" text, "Name" text, "Street_address" text, "Years_as_tallest" text, "Height_feet" int, "Floors" int, PRIMARY KEY("building_id") ) 3 rows from building table: building_id Name Street_address Years_as_tallest Height_feet Floors 0 Citizens Bank Building 701 North Franklin Street 1913–1915 145 12 1 Tampa City Hall 315 John F. Kennedy Boulevard 1915–1926 160 10 2 Floridan Hotel 905 Franklin Street 1926–1966 204 17 CREATE TABLE "Institution" ( "Institution_id" text, "Institution" text, "Location" text, "Founded" real, "Type" text, "Enrollment" int, "Team" text, "Primary_Conference" text, "building_id" text, PRIMARY KEY("Institution_id"), FOREIGN KEY ("building_id") REFERENCES "building"("building_id") ) 3 rows from Institution table: Institution_id Institution Location Founded Type Enrollment Team Primary_Conference building_id 0 Ave Maria University Ave Maria, Florida 1998.0 Private 1200 Gyrenes The Sun 1 1 Dakota State University Madison, South Dakota 1881.0 Public 3102 Trojans none 1 2 Edward Waters College Jacksonville, Florida 1866.0 Private 800 Tigers Gulf Coast (GCAC) 3 CREATE TABLE "protein" ( "common_name" text, "protein_name" text, "divergence_from_human_lineage" real, "accession_number" text, "sequence_length" real, "sequence_identity_to_human_protein" text, "Institution_id" text, PRIMARY KEY("common_name"), FOREIGN KEY("Institution_id") REFERENCES "Institution"("Institution_id") ) 3 rows from protein table: common_name protein_name divergence_from_human_lineage accession_number sequence_length sequence_identity_to_human_protein Institution_id Tropical Clawed Frog uncharacterized protein C20orf117-like 371.2 XP_002942331.1 1584.0 39% 1 purple sea urchin uncharacterized protein LOC578090 742.9 XP_783370.2 1587.0 47% 3 body louse Centromeric protein E, putative 782.7 XP_002429877.1 2086.0 30% 5
protein_institute
Show the number of buildings with a height above the average or a number of floors above the average.
SELECT count(*) FROM building WHERE height_feet > (SELECT avg(height_feet) FROM building) OR floors > (SELECT avg(floors) FROM building)
CREATE TABLE "building" ( "building_id" text, "Name" text, "Street_address" text, "Years_as_tallest" text, "Height_feet" int, "Floors" int, PRIMARY KEY("building_id") ) 3 rows from building table: building_id Name Street_address Years_as_tallest Height_feet Floors 0 Citizens Bank Building 701 North Franklin Street 1913–1915 145 12 1 Tampa City Hall 315 John F. Kennedy Boulevard 1915–1926 160 10 2 Floridan Hotel 905 Franklin Street 1926–1966 204 17 CREATE TABLE "Institution" ( "Institution_id" text, "Institution" text, "Location" text, "Founded" real, "Type" text, "Enrollment" int, "Team" text, "Primary_Conference" text, "building_id" text, PRIMARY KEY("Institution_id"), FOREIGN KEY ("building_id") REFERENCES "building"("building_id") ) 3 rows from Institution table: Institution_id Institution Location Founded Type Enrollment Team Primary_Conference building_id 0 Ave Maria University Ave Maria, Florida 1998.0 Private 1200 Gyrenes The Sun 1 1 Dakota State University Madison, South Dakota 1881.0 Public 3102 Trojans none 1 2 Edward Waters College Jacksonville, Florida 1866.0 Private 800 Tigers Gulf Coast (GCAC) 3 CREATE TABLE "protein" ( "common_name" text, "protein_name" text, "divergence_from_human_lineage" real, "accession_number" text, "sequence_length" real, "sequence_identity_to_human_protein" text, "Institution_id" text, PRIMARY KEY("common_name"), FOREIGN KEY("Institution_id") REFERENCES "Institution"("Institution_id") ) 3 rows from protein table: common_name protein_name divergence_from_human_lineage accession_number sequence_length sequence_identity_to_human_protein Institution_id Tropical Clawed Frog uncharacterized protein C20orf117-like 371.2 XP_002942331.1 1584.0 39% 1 purple sea urchin uncharacterized protein LOC578090 742.9 XP_783370.2 1587.0 47% 3 body louse Centromeric protein E, putative 782.7 XP_002429877.1 2086.0 30% 5
protein_institute
List the names of buildings with at least 200 feet of height and with at least 20 floors.
SELECT name FROM building WHERE height_feet >= 200 AND floors >= 20
CREATE TABLE "building" ( "building_id" text, "Name" text, "Street_address" text, "Years_as_tallest" text, "Height_feet" int, "Floors" int, PRIMARY KEY("building_id") ) 3 rows from building table: building_id Name Street_address Years_as_tallest Height_feet Floors 0 Citizens Bank Building 701 North Franklin Street 1913–1915 145 12 1 Tampa City Hall 315 John F. Kennedy Boulevard 1915–1926 160 10 2 Floridan Hotel 905 Franklin Street 1926–1966 204 17 CREATE TABLE "Institution" ( "Institution_id" text, "Institution" text, "Location" text, "Founded" real, "Type" text, "Enrollment" int, "Team" text, "Primary_Conference" text, "building_id" text, PRIMARY KEY("Institution_id"), FOREIGN KEY ("building_id") REFERENCES "building"("building_id") ) 3 rows from Institution table: Institution_id Institution Location Founded Type Enrollment Team Primary_Conference building_id 0 Ave Maria University Ave Maria, Florida 1998.0 Private 1200 Gyrenes The Sun 1 1 Dakota State University Madison, South Dakota 1881.0 Public 3102 Trojans none 1 2 Edward Waters College Jacksonville, Florida 1866.0 Private 800 Tigers Gulf Coast (GCAC) 3 CREATE TABLE "protein" ( "common_name" text, "protein_name" text, "divergence_from_human_lineage" real, "accession_number" text, "sequence_length" real, "sequence_identity_to_human_protein" text, "Institution_id" text, PRIMARY KEY("common_name"), FOREIGN KEY("Institution_id") REFERENCES "Institution"("Institution_id") ) 3 rows from protein table: common_name protein_name divergence_from_human_lineage accession_number sequence_length sequence_identity_to_human_protein Institution_id Tropical Clawed Frog uncharacterized protein C20orf117-like 371.2 XP_002942331.1 1584.0 39% 1 purple sea urchin uncharacterized protein LOC578090 742.9 XP_783370.2 1587.0 47% 3 body louse Centromeric protein E, putative 782.7 XP_002429877.1 2086.0 30% 5
protein_institute
Show the names and locations of institutions that are founded after 1990 and have the type "Private".
SELECT institution , LOCATION FROM institution WHERE founded > 1990 AND TYPE = 'Private'
CREATE TABLE "building" ( "building_id" text, "Name" text, "Street_address" text, "Years_as_tallest" text, "Height_feet" int, "Floors" int, PRIMARY KEY("building_id") ) 3 rows from building table: building_id Name Street_address Years_as_tallest Height_feet Floors 0 Citizens Bank Building 701 North Franklin Street 1913–1915 145 12 1 Tampa City Hall 315 John F. Kennedy Boulevard 1915–1926 160 10 2 Floridan Hotel 905 Franklin Street 1926–1966 204 17 CREATE TABLE "Institution" ( "Institution_id" text, "Institution" text, "Location" text, "Founded" real, "Type" text, "Enrollment" int, "Team" text, "Primary_Conference" text, "building_id" text, PRIMARY KEY("Institution_id"), FOREIGN KEY ("building_id") REFERENCES "building"("building_id") ) 3 rows from Institution table: Institution_id Institution Location Founded Type Enrollment Team Primary_Conference building_id 0 Ave Maria University Ave Maria, Florida 1998.0 Private 1200 Gyrenes The Sun 1 1 Dakota State University Madison, South Dakota 1881.0 Public 3102 Trojans none 1 2 Edward Waters College Jacksonville, Florida 1866.0 Private 800 Tigers Gulf Coast (GCAC) 3 CREATE TABLE "protein" ( "common_name" text, "protein_name" text, "divergence_from_human_lineage" real, "accession_number" text, "sequence_length" real, "sequence_identity_to_human_protein" text, "Institution_id" text, PRIMARY KEY("common_name"), FOREIGN KEY("Institution_id") REFERENCES "Institution"("Institution_id") ) 3 rows from protein table: common_name protein_name divergence_from_human_lineage accession_number sequence_length sequence_identity_to_human_protein Institution_id Tropical Clawed Frog uncharacterized protein C20orf117-like 371.2 XP_002942331.1 1584.0 39% 1 purple sea urchin uncharacterized protein LOC578090 742.9 XP_783370.2 1587.0 47% 3 body louse Centromeric protein E, putative 782.7 XP_002429877.1 2086.0 30% 5
protein_institute
Show institution types, along with the number of institutions and total enrollment for each type.
SELECT TYPE , count(*) , sum(enrollment) FROM institution GROUP BY TYPE
CREATE TABLE "building" ( "building_id" text, "Name" text, "Street_address" text, "Years_as_tallest" text, "Height_feet" int, "Floors" int, PRIMARY KEY("building_id") ) 3 rows from building table: building_id Name Street_address Years_as_tallest Height_feet Floors 0 Citizens Bank Building 701 North Franklin Street 1913–1915 145 12 1 Tampa City Hall 315 John F. Kennedy Boulevard 1915–1926 160 10 2 Floridan Hotel 905 Franklin Street 1926–1966 204 17 CREATE TABLE "Institution" ( "Institution_id" text, "Institution" text, "Location" text, "Founded" real, "Type" text, "Enrollment" int, "Team" text, "Primary_Conference" text, "building_id" text, PRIMARY KEY("Institution_id"), FOREIGN KEY ("building_id") REFERENCES "building"("building_id") ) 3 rows from Institution table: Institution_id Institution Location Founded Type Enrollment Team Primary_Conference building_id 0 Ave Maria University Ave Maria, Florida 1998.0 Private 1200 Gyrenes The Sun 1 1 Dakota State University Madison, South Dakota 1881.0 Public 3102 Trojans none 1 2 Edward Waters College Jacksonville, Florida 1866.0 Private 800 Tigers Gulf Coast (GCAC) 3 CREATE TABLE "protein" ( "common_name" text, "protein_name" text, "divergence_from_human_lineage" real, "accession_number" text, "sequence_length" real, "sequence_identity_to_human_protein" text, "Institution_id" text, PRIMARY KEY("common_name"), FOREIGN KEY("Institution_id") REFERENCES "Institution"("Institution_id") ) 3 rows from protein table: common_name protein_name divergence_from_human_lineage accession_number sequence_length sequence_identity_to_human_protein Institution_id Tropical Clawed Frog uncharacterized protein C20orf117-like 371.2 XP_002942331.1 1584.0 39% 1 purple sea urchin uncharacterized protein LOC578090 742.9 XP_783370.2 1587.0 47% 3 body louse Centromeric protein E, putative 782.7 XP_002429877.1 2086.0 30% 5
protein_institute
Show the institution type with the largest number of institutions.
SELECT TYPE FROM institution GROUP BY TYPE ORDER BY count(*) DESC LIMIT 1
CREATE TABLE "building" ( "building_id" text, "Name" text, "Street_address" text, "Years_as_tallest" text, "Height_feet" int, "Floors" int, PRIMARY KEY("building_id") ) 3 rows from building table: building_id Name Street_address Years_as_tallest Height_feet Floors 0 Citizens Bank Building 701 North Franklin Street 1913–1915 145 12 1 Tampa City Hall 315 John F. Kennedy Boulevard 1915–1926 160 10 2 Floridan Hotel 905 Franklin Street 1926–1966 204 17 CREATE TABLE "Institution" ( "Institution_id" text, "Institution" text, "Location" text, "Founded" real, "Type" text, "Enrollment" int, "Team" text, "Primary_Conference" text, "building_id" text, PRIMARY KEY("Institution_id"), FOREIGN KEY ("building_id") REFERENCES "building"("building_id") ) 3 rows from Institution table: Institution_id Institution Location Founded Type Enrollment Team Primary_Conference building_id 0 Ave Maria University Ave Maria, Florida 1998.0 Private 1200 Gyrenes The Sun 1 1 Dakota State University Madison, South Dakota 1881.0 Public 3102 Trojans none 1 2 Edward Waters College Jacksonville, Florida 1866.0 Private 800 Tigers Gulf Coast (GCAC) 3 CREATE TABLE "protein" ( "common_name" text, "protein_name" text, "divergence_from_human_lineage" real, "accession_number" text, "sequence_length" real, "sequence_identity_to_human_protein" text, "Institution_id" text, PRIMARY KEY("common_name"), FOREIGN KEY("Institution_id") REFERENCES "Institution"("Institution_id") ) 3 rows from protein table: common_name protein_name divergence_from_human_lineage accession_number sequence_length sequence_identity_to_human_protein Institution_id Tropical Clawed Frog uncharacterized protein C20orf117-like 371.2 XP_002942331.1 1584.0 39% 1 purple sea urchin uncharacterized protein LOC578090 742.9 XP_783370.2 1587.0 47% 3 body louse Centromeric protein E, putative 782.7 XP_002429877.1 2086.0 30% 5
protein_institute
Show the institution type with an institution founded after 1990 and an institution with at least 1000 enrollment.
SELECT TYPE FROM institution WHERE founded > 1990 AND enrollment >= 1000
CREATE TABLE "building" ( "building_id" text, "Name" text, "Street_address" text, "Years_as_tallest" text, "Height_feet" int, "Floors" int, PRIMARY KEY("building_id") ) 3 rows from building table: building_id Name Street_address Years_as_tallest Height_feet Floors 0 Citizens Bank Building 701 North Franklin Street 1913–1915 145 12 1 Tampa City Hall 315 John F. Kennedy Boulevard 1915–1926 160 10 2 Floridan Hotel 905 Franklin Street 1926–1966 204 17 CREATE TABLE "Institution" ( "Institution_id" text, "Institution" text, "Location" text, "Founded" real, "Type" text, "Enrollment" int, "Team" text, "Primary_Conference" text, "building_id" text, PRIMARY KEY("Institution_id"), FOREIGN KEY ("building_id") REFERENCES "building"("building_id") ) 3 rows from Institution table: Institution_id Institution Location Founded Type Enrollment Team Primary_Conference building_id 0 Ave Maria University Ave Maria, Florida 1998.0 Private 1200 Gyrenes The Sun 1 1 Dakota State University Madison, South Dakota 1881.0 Public 3102 Trojans none 1 2 Edward Waters College Jacksonville, Florida 1866.0 Private 800 Tigers Gulf Coast (GCAC) 3 CREATE TABLE "protein" ( "common_name" text, "protein_name" text, "divergence_from_human_lineage" real, "accession_number" text, "sequence_length" real, "sequence_identity_to_human_protein" text, "Institution_id" text, PRIMARY KEY("common_name"), FOREIGN KEY("Institution_id") REFERENCES "Institution"("Institution_id") ) 3 rows from protein table: common_name protein_name divergence_from_human_lineage accession_number sequence_length sequence_identity_to_human_protein Institution_id Tropical Clawed Frog uncharacterized protein C20orf117-like 371.2 XP_002942331.1 1584.0 39% 1 purple sea urchin uncharacterized protein LOC578090 742.9 XP_783370.2 1587.0 47% 3 body louse Centromeric protein E, putative 782.7 XP_002429877.1 2086.0 30% 5
protein_institute
Show the name of buildings that do not have any institution.
SELECT name FROM building WHERE building_id NOT IN (SELECT building_id FROM institution)
CREATE TABLE "building" ( "building_id" text, "Name" text, "Street_address" text, "Years_as_tallest" text, "Height_feet" int, "Floors" int, PRIMARY KEY("building_id") ) 3 rows from building table: building_id Name Street_address Years_as_tallest Height_feet Floors 0 Citizens Bank Building 701 North Franklin Street 1913–1915 145 12 1 Tampa City Hall 315 John F. Kennedy Boulevard 1915–1926 160 10 2 Floridan Hotel 905 Franklin Street 1926–1966 204 17 CREATE TABLE "Institution" ( "Institution_id" text, "Institution" text, "Location" text, "Founded" real, "Type" text, "Enrollment" int, "Team" text, "Primary_Conference" text, "building_id" text, PRIMARY KEY("Institution_id"), FOREIGN KEY ("building_id") REFERENCES "building"("building_id") ) 3 rows from Institution table: Institution_id Institution Location Founded Type Enrollment Team Primary_Conference building_id 0 Ave Maria University Ave Maria, Florida 1998.0 Private 1200 Gyrenes The Sun 1 1 Dakota State University Madison, South Dakota 1881.0 Public 3102 Trojans none 1 2 Edward Waters College Jacksonville, Florida 1866.0 Private 800 Tigers Gulf Coast (GCAC) 3 CREATE TABLE "protein" ( "common_name" text, "protein_name" text, "divergence_from_human_lineage" real, "accession_number" text, "sequence_length" real, "sequence_identity_to_human_protein" text, "Institution_id" text, PRIMARY KEY("common_name"), FOREIGN KEY("Institution_id") REFERENCES "Institution"("Institution_id") ) 3 rows from protein table: common_name protein_name divergence_from_human_lineage accession_number sequence_length sequence_identity_to_human_protein Institution_id Tropical Clawed Frog uncharacterized protein C20orf117-like 371.2 XP_002942331.1 1584.0 39% 1 purple sea urchin uncharacterized protein LOC578090 742.9 XP_783370.2 1587.0 47% 3 body louse Centromeric protein E, putative 782.7 XP_002429877.1 2086.0 30% 5
protein_institute
Show the names of buildings except for those having an institution founded in 2003.
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
CREATE TABLE "building" ( "building_id" text, "Name" text, "Street_address" text, "Years_as_tallest" text, "Height_feet" int, "Floors" int, PRIMARY KEY("building_id") ) 3 rows from building table: building_id Name Street_address Years_as_tallest Height_feet Floors 0 Citizens Bank Building 701 North Franklin Street 1913–1915 145 12 1 Tampa City Hall 315 John F. Kennedy Boulevard 1915–1926 160 10 2 Floridan Hotel 905 Franklin Street 1926–1966 204 17 CREATE TABLE "Institution" ( "Institution_id" text, "Institution" text, "Location" text, "Founded" real, "Type" text, "Enrollment" int, "Team" text, "Primary_Conference" text, "building_id" text, PRIMARY KEY("Institution_id"), FOREIGN KEY ("building_id") REFERENCES "building"("building_id") ) 3 rows from Institution table: Institution_id Institution Location Founded Type Enrollment Team Primary_Conference building_id 0 Ave Maria University Ave Maria, Florida 1998.0 Private 1200 Gyrenes The Sun 1 1 Dakota State University Madison, South Dakota 1881.0 Public 3102 Trojans none 1 2 Edward Waters College Jacksonville, Florida 1866.0 Private 800 Tigers Gulf Coast (GCAC) 3 CREATE TABLE "protein" ( "common_name" text, "protein_name" text, "divergence_from_human_lineage" real, "accession_number" text, "sequence_length" real, "sequence_identity_to_human_protein" text, "Institution_id" text, PRIMARY KEY("common_name"), FOREIGN KEY("Institution_id") REFERENCES "Institution"("Institution_id") ) 3 rows from protein table: common_name protein_name divergence_from_human_lineage accession_number sequence_length sequence_identity_to_human_protein Institution_id Tropical Clawed Frog uncharacterized protein C20orf117-like 371.2 XP_002942331.1 1584.0 39% 1 purple sea urchin uncharacterized protein LOC578090 742.9 XP_783370.2 1587.0 47% 3 body louse Centromeric protein E, putative 782.7 XP_002429877.1 2086.0 30% 5
protein_institute
For each building, show the name of the building and the number of institutions in it.
SELECT T1.name , count(*) FROM building AS T1 JOIN institution AS T2 ON T1.building_id = T2.building_id GROUP BY T1.building_id
CREATE TABLE "building" ( "building_id" text, "Name" text, "Street_address" text, "Years_as_tallest" text, "Height_feet" int, "Floors" int, PRIMARY KEY("building_id") ) 3 rows from building table: building_id Name Street_address Years_as_tallest Height_feet Floors 0 Citizens Bank Building 701 North Franklin Street 1913–1915 145 12 1 Tampa City Hall 315 John F. Kennedy Boulevard 1915–1926 160 10 2 Floridan Hotel 905 Franklin Street 1926–1966 204 17 CREATE TABLE "Institution" ( "Institution_id" text, "Institution" text, "Location" text, "Founded" real, "Type" text, "Enrollment" int, "Team" text, "Primary_Conference" text, "building_id" text, PRIMARY KEY("Institution_id"), FOREIGN KEY ("building_id") REFERENCES "building"("building_id") ) 3 rows from Institution table: Institution_id Institution Location Founded Type Enrollment Team Primary_Conference building_id 0 Ave Maria University Ave Maria, Florida 1998.0 Private 1200 Gyrenes The Sun 1 1 Dakota State University Madison, South Dakota 1881.0 Public 3102 Trojans none 1 2 Edward Waters College Jacksonville, Florida 1866.0 Private 800 Tigers Gulf Coast (GCAC) 3 CREATE TABLE "protein" ( "common_name" text, "protein_name" text, "divergence_from_human_lineage" real, "accession_number" text, "sequence_length" real, "sequence_identity_to_human_protein" text, "Institution_id" text, PRIMARY KEY("common_name"), FOREIGN KEY("Institution_id") REFERENCES "Institution"("Institution_id") ) 3 rows from protein table: common_name protein_name divergence_from_human_lineage accession_number sequence_length sequence_identity_to_human_protein Institution_id Tropical Clawed Frog uncharacterized protein C20orf117-like 371.2 XP_002942331.1 1584.0 39% 1 purple sea urchin uncharacterized protein LOC578090 742.9 XP_783370.2 1587.0 47% 3 body louse Centromeric protein E, putative 782.7 XP_002429877.1 2086.0 30% 5
protein_institute
Show the names and heights of buildings with at least two institutions founded after 1880.
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
CREATE TABLE "building" ( "building_id" text, "Name" text, "Street_address" text, "Years_as_tallest" text, "Height_feet" int, "Floors" int, PRIMARY KEY("building_id") ) 3 rows from building table: building_id Name Street_address Years_as_tallest Height_feet Floors 0 Citizens Bank Building 701 North Franklin Street 1913–1915 145 12 1 Tampa City Hall 315 John F. Kennedy Boulevard 1915–1926 160 10 2 Floridan Hotel 905 Franklin Street 1926–1966 204 17 CREATE TABLE "Institution" ( "Institution_id" text, "Institution" text, "Location" text, "Founded" real, "Type" text, "Enrollment" int, "Team" text, "Primary_Conference" text, "building_id" text, PRIMARY KEY("Institution_id"), FOREIGN KEY ("building_id") REFERENCES "building"("building_id") ) 3 rows from Institution table: Institution_id Institution Location Founded Type Enrollment Team Primary_Conference building_id 0 Ave Maria University Ave Maria, Florida 1998.0 Private 1200 Gyrenes The Sun 1 1 Dakota State University Madison, South Dakota 1881.0 Public 3102 Trojans none 1 2 Edward Waters College Jacksonville, Florida 1866.0 Private 800 Tigers Gulf Coast (GCAC) 3 CREATE TABLE "protein" ( "common_name" text, "protein_name" text, "divergence_from_human_lineage" real, "accession_number" text, "sequence_length" real, "sequence_identity_to_human_protein" text, "Institution_id" text, PRIMARY KEY("common_name"), FOREIGN KEY("Institution_id") REFERENCES "Institution"("Institution_id") ) 3 rows from protein table: common_name protein_name divergence_from_human_lineage accession_number sequence_length sequence_identity_to_human_protein Institution_id Tropical Clawed Frog uncharacterized protein C20orf117-like 371.2 XP_002942331.1 1584.0 39% 1 purple sea urchin uncharacterized protein LOC578090 742.9 XP_783370.2 1587.0 47% 3 body louse Centromeric protein E, putative 782.7 XP_002429877.1 2086.0 30% 5
protein_institute
Show all the distinct institution types.
SELECT DISTINCT TYPE FROM institution
CREATE TABLE "building" ( "building_id" text, "Name" text, "Street_address" text, "Years_as_tallest" text, "Height_feet" int, "Floors" int, PRIMARY KEY("building_id") ) 3 rows from building table: building_id Name Street_address Years_as_tallest Height_feet Floors 0 Citizens Bank Building 701 North Franklin Street 1913–1915 145 12 1 Tampa City Hall 315 John F. Kennedy Boulevard 1915–1926 160 10 2 Floridan Hotel 905 Franklin Street 1926–1966 204 17 CREATE TABLE "Institution" ( "Institution_id" text, "Institution" text, "Location" text, "Founded" real, "Type" text, "Enrollment" int, "Team" text, "Primary_Conference" text, "building_id" text, PRIMARY KEY("Institution_id"), FOREIGN KEY ("building_id") REFERENCES "building"("building_id") ) 3 rows from Institution table: Institution_id Institution Location Founded Type Enrollment Team Primary_Conference building_id 0 Ave Maria University Ave Maria, Florida 1998.0 Private 1200 Gyrenes The Sun 1 1 Dakota State University Madison, South Dakota 1881.0 Public 3102 Trojans none 1 2 Edward Waters College Jacksonville, Florida 1866.0 Private 800 Tigers Gulf Coast (GCAC) 3 CREATE TABLE "protein" ( "common_name" text, "protein_name" text, "divergence_from_human_lineage" real, "accession_number" text, "sequence_length" real, "sequence_identity_to_human_protein" text, "Institution_id" text, PRIMARY KEY("common_name"), FOREIGN KEY("Institution_id") REFERENCES "Institution"("Institution_id") ) 3 rows from protein table: common_name protein_name divergence_from_human_lineage accession_number sequence_length sequence_identity_to_human_protein Institution_id Tropical Clawed Frog uncharacterized protein C20orf117-like 371.2 XP_002942331.1 1584.0 39% 1 purple sea urchin uncharacterized protein LOC578090 742.9 XP_783370.2 1587.0 47% 3 body louse Centromeric protein E, putative 782.7 XP_002429877.1 2086.0 30% 5
protein_institute
Show institution names along with the number of proteins for each institution.
SELECT T1.institution , count(*) FROM institution AS T1 JOIN protein AS T2 ON T1.institution_id = T2.institution_id GROUP BY T1.institution_id
CREATE TABLE "building" ( "building_id" text, "Name" text, "Street_address" text, "Years_as_tallest" text, "Height_feet" int, "Floors" int, PRIMARY KEY("building_id") ) 3 rows from building table: building_id Name Street_address Years_as_tallest Height_feet Floors 0 Citizens Bank Building 701 North Franklin Street 1913–1915 145 12 1 Tampa City Hall 315 John F. Kennedy Boulevard 1915–1926 160 10 2 Floridan Hotel 905 Franklin Street 1926–1966 204 17 CREATE TABLE "Institution" ( "Institution_id" text, "Institution" text, "Location" text, "Founded" real, "Type" text, "Enrollment" int, "Team" text, "Primary_Conference" text, "building_id" text, PRIMARY KEY("Institution_id"), FOREIGN KEY ("building_id") REFERENCES "building"("building_id") ) 3 rows from Institution table: Institution_id Institution Location Founded Type Enrollment Team Primary_Conference building_id 0 Ave Maria University Ave Maria, Florida 1998.0 Private 1200 Gyrenes The Sun 1 1 Dakota State University Madison, South Dakota 1881.0 Public 3102 Trojans none 1 2 Edward Waters College Jacksonville, Florida 1866.0 Private 800 Tigers Gulf Coast (GCAC) 3 CREATE TABLE "protein" ( "common_name" text, "protein_name" text, "divergence_from_human_lineage" real, "accession_number" text, "sequence_length" real, "sequence_identity_to_human_protein" text, "Institution_id" text, PRIMARY KEY("common_name"), FOREIGN KEY("Institution_id") REFERENCES "Institution"("Institution_id") ) 3 rows from protein table: common_name protein_name divergence_from_human_lineage accession_number sequence_length sequence_identity_to_human_protein Institution_id Tropical Clawed Frog uncharacterized protein C20orf117-like 371.2 XP_002942331.1 1584.0 39% 1 purple sea urchin uncharacterized protein LOC578090 742.9 XP_783370.2 1587.0 47% 3 body louse Centromeric protein E, putative 782.7 XP_002429877.1 2086.0 30% 5
protein_institute
How many proteins are associated with an institution founded after 1880 or an institution with type "Private"?
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'
CREATE TABLE "building" ( "building_id" text, "Name" text, "Street_address" text, "Years_as_tallest" text, "Height_feet" int, "Floors" int, PRIMARY KEY("building_id") ) 3 rows from building table: building_id Name Street_address Years_as_tallest Height_feet Floors 0 Citizens Bank Building 701 North Franklin Street 1913–1915 145 12 1 Tampa City Hall 315 John F. Kennedy Boulevard 1915–1926 160 10 2 Floridan Hotel 905 Franklin Street 1926–1966 204 17 CREATE TABLE "Institution" ( "Institution_id" text, "Institution" text, "Location" text, "Founded" real, "Type" text, "Enrollment" int, "Team" text, "Primary_Conference" text, "building_id" text, PRIMARY KEY("Institution_id"), FOREIGN KEY ("building_id") REFERENCES "building"("building_id") ) 3 rows from Institution table: Institution_id Institution Location Founded Type Enrollment Team Primary_Conference building_id 0 Ave Maria University Ave Maria, Florida 1998.0 Private 1200 Gyrenes The Sun 1 1 Dakota State University Madison, South Dakota 1881.0 Public 3102 Trojans none 1 2 Edward Waters College Jacksonville, Florida 1866.0 Private 800 Tigers Gulf Coast (GCAC) 3 CREATE TABLE "protein" ( "common_name" text, "protein_name" text, "divergence_from_human_lineage" real, "accession_number" text, "sequence_length" real, "sequence_identity_to_human_protein" text, "Institution_id" text, PRIMARY KEY("common_name"), FOREIGN KEY("Institution_id") REFERENCES "Institution"("Institution_id") ) 3 rows from protein table: common_name protein_name divergence_from_human_lineage accession_number sequence_length sequence_identity_to_human_protein Institution_id Tropical Clawed Frog uncharacterized protein C20orf117-like 371.2 XP_002942331.1 1584.0 39% 1 purple sea urchin uncharacterized protein LOC578090 742.9 XP_783370.2 1587.0 47% 3 body louse Centromeric protein E, putative 782.7 XP_002429877.1 2086.0 30% 5
protein_institute
Show the protein name and the institution name.
SELECT T2.protein_name , T1.institution FROM institution AS T1 JOIN protein AS T2 ON T1.institution_id = T2.institution_id
CREATE TABLE "building" ( "building_id" text, "Name" text, "Street_address" text, "Years_as_tallest" text, "Height_feet" int, "Floors" int, PRIMARY KEY("building_id") ) 3 rows from building table: building_id Name Street_address Years_as_tallest Height_feet Floors 0 Citizens Bank Building 701 North Franklin Street 1913–1915 145 12 1 Tampa City Hall 315 John F. Kennedy Boulevard 1915–1926 160 10 2 Floridan Hotel 905 Franklin Street 1926–1966 204 17 CREATE TABLE "Institution" ( "Institution_id" text, "Institution" text, "Location" text, "Founded" real, "Type" text, "Enrollment" int, "Team" text, "Primary_Conference" text, "building_id" text, PRIMARY KEY("Institution_id"), FOREIGN KEY ("building_id") REFERENCES "building"("building_id") ) 3 rows from Institution table: Institution_id Institution Location Founded Type Enrollment Team Primary_Conference building_id 0 Ave Maria University Ave Maria, Florida 1998.0 Private 1200 Gyrenes The Sun 1 1 Dakota State University Madison, South Dakota 1881.0 Public 3102 Trojans none 1 2 Edward Waters College Jacksonville, Florida 1866.0 Private 800 Tigers Gulf Coast (GCAC) 3 CREATE TABLE "protein" ( "common_name" text, "protein_name" text, "divergence_from_human_lineage" real, "accession_number" text, "sequence_length" real, "sequence_identity_to_human_protein" text, "Institution_id" text, PRIMARY KEY("common_name"), FOREIGN KEY("Institution_id") REFERENCES "Institution"("Institution_id") ) 3 rows from protein table: common_name protein_name divergence_from_human_lineage accession_number sequence_length sequence_identity_to_human_protein Institution_id Tropical Clawed Frog uncharacterized protein C20orf117-like 371.2 XP_002942331.1 1584.0 39% 1 purple sea urchin uncharacterized protein LOC578090 742.9 XP_783370.2 1587.0 47% 3 body louse Centromeric protein E, putative 782.7 XP_002429877.1 2086.0 30% 5
protein_institute
How many proteins are associated with an institution in a building with at least 20 floors?
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
CREATE TABLE "building" ( "building_id" text, "Name" text, "Street_address" text, "Years_as_tallest" text, "Height_feet" int, "Floors" int, PRIMARY KEY("building_id") ) 3 rows from building table: building_id Name Street_address Years_as_tallest Height_feet Floors 0 Citizens Bank Building 701 North Franklin Street 1913–1915 145 12 1 Tampa City Hall 315 John F. Kennedy Boulevard 1915–1926 160 10 2 Floridan Hotel 905 Franklin Street 1926–1966 204 17 CREATE TABLE "Institution" ( "Institution_id" text, "Institution" text, "Location" text, "Founded" real, "Type" text, "Enrollment" int, "Team" text, "Primary_Conference" text, "building_id" text, PRIMARY KEY("Institution_id"), FOREIGN KEY ("building_id") REFERENCES "building"("building_id") ) 3 rows from Institution table: Institution_id Institution Location Founded Type Enrollment Team Primary_Conference building_id 0 Ave Maria University Ave Maria, Florida 1998.0 Private 1200 Gyrenes The Sun 1 1 Dakota State University Madison, South Dakota 1881.0 Public 3102 Trojans none 1 2 Edward Waters College Jacksonville, Florida 1866.0 Private 800 Tigers Gulf Coast (GCAC) 3 CREATE TABLE "protein" ( "common_name" text, "protein_name" text, "divergence_from_human_lineage" real, "accession_number" text, "sequence_length" real, "sequence_identity_to_human_protein" text, "Institution_id" text, PRIMARY KEY("common_name"), FOREIGN KEY("Institution_id") REFERENCES "Institution"("Institution_id") ) 3 rows from protein table: common_name protein_name divergence_from_human_lineage accession_number sequence_length sequence_identity_to_human_protein Institution_id Tropical Clawed Frog uncharacterized protein C20orf117-like 371.2 XP_002942331.1 1584.0 39% 1 purple sea urchin uncharacterized protein LOC578090 742.9 XP_783370.2 1587.0 47% 3 body louse Centromeric protein E, putative 782.7 XP_002429877.1 2086.0 30% 5
protein_institute
How many institutions do not have an associated protein in our record?
SELECT count(*) FROM institution WHERE institution_id NOT IN (SELECT institution_id FROM protein)
CREATE TABLE "building" ( "building_id" text, "Name" text, "Street_address" text, "Years_as_tallest" text, "Height_feet" int, "Floors" int, PRIMARY KEY("building_id") ) 3 rows from building table: building_id Name Street_address Years_as_tallest Height_feet Floors 0 Citizens Bank Building 701 North Franklin Street 1913–1915 145 12 1 Tampa City Hall 315 John F. Kennedy Boulevard 1915–1926 160 10 2 Floridan Hotel 905 Franklin Street 1926–1966 204 17 CREATE TABLE "Institution" ( "Institution_id" text, "Institution" text, "Location" text, "Founded" real, "Type" text, "Enrollment" int, "Team" text, "Primary_Conference" text, "building_id" text, PRIMARY KEY("Institution_id"), FOREIGN KEY ("building_id") REFERENCES "building"("building_id") ) 3 rows from Institution table: Institution_id Institution Location Founded Type Enrollment Team Primary_Conference building_id 0 Ave Maria University Ave Maria, Florida 1998.0 Private 1200 Gyrenes The Sun 1 1 Dakota State University Madison, South Dakota 1881.0 Public 3102 Trojans none 1 2 Edward Waters College Jacksonville, Florida 1866.0 Private 800 Tigers Gulf Coast (GCAC) 3 CREATE TABLE "protein" ( "common_name" text, "protein_name" text, "divergence_from_human_lineage" real, "accession_number" text, "sequence_length" real, "sequence_identity_to_human_protein" text, "Institution_id" text, PRIMARY KEY("common_name"), FOREIGN KEY("Institution_id") REFERENCES "Institution"("Institution_id") ) 3 rows from protein table: common_name protein_name divergence_from_human_lineage accession_number sequence_length sequence_identity_to_human_protein Institution_id Tropical Clawed Frog uncharacterized protein C20orf117-like 371.2 XP_002942331.1 1584.0 39% 1 purple sea urchin uncharacterized protein LOC578090 742.9 XP_783370.2 1587.0 47% 3 body louse Centromeric protein E, putative 782.7 XP_002429877.1 2086.0 30% 5
cinema
Show all the locations where no cinema has capacity over 800.
SELECT LOCATION FROM cinema EXCEPT SELECT LOCATION FROM cinema WHERE capacity > 800
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
Show all the locations where some cinemas were opened in both year 2010 and year 2011.
SELECT LOCATION FROM cinema WHERE openning_year = 2010 INTERSECT SELECT LOCATION FROM cinema WHERE openning_year = 2011
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
How many cinema do we have?
SELECT count(*) FROM cinema
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
Count the number of cinemas.
SELECT count(*) FROM cinema
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
Show name, opening year, and capacity for each cinema.
SELECT name , openning_year , capacity FROM cinema
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
Show the cinema name and location for cinemas with capacity above average.
SELECT name , LOCATION FROM cinema WHERE capacity > (SELECT avg(capacity) FROM cinema)
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
What are all the locations with a cinema?
SELECT DISTINCT LOCATION FROM cinema
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
Find the distinct locations that has a cinema.
SELECT DISTINCT LOCATION FROM cinema
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
Show all the cinema names and opening years in descending order of opening year.
SELECT name , openning_year FROM cinema ORDER BY openning_year DESC
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
What are the name and location of the cinema with the largest capacity?
SELECT name , LOCATION FROM cinema ORDER BY capacity DESC LIMIT 1
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
Show the average, minimum, and maximum capacity for all the cinemas opened in year 2011 or later.
SELECT avg(capacity) , min(capacity) , max(capacity) FROM cinema WHERE openning_year >= 2011
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
Show each location and the number of cinemas there.
SELECT LOCATION , count(*) FROM cinema GROUP BY LOCATION
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
What is the location with the most cinemas opened in year 2010 or later?
SELECT LOCATION FROM cinema WHERE openning_year >= 2010 GROUP BY LOCATION ORDER BY count(*) DESC LIMIT 1
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
Show all the locations with at least two cinemas with capacity above 300.
SELECT LOCATION FROM cinema WHERE capacity > 300 GROUP BY LOCATION HAVING count(*) >= 2
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
Which locations have 2 or more cinemas with capacity over 300?
SELECT LOCATION FROM cinema WHERE capacity > 300 GROUP BY LOCATION HAVING count(*) >= 2
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
Show the title and director for all films.
SELECT title , directed_by FROM film
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
What are the title and director of each film?
SELECT title , directed_by FROM film
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
Show all directors.
SELECT DISTINCT directed_by FROM film
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
Who are all the directors?
SELECT DISTINCT directed_by FROM film
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
List all directors along with the number of films directed by each director.
SELECT directed_by , count(*) FROM film GROUP BY directed_by
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
What is total number of show times per dat for each cinema?
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
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
What are the title and maximum price of each film?
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
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
Give me the title and highest price for each film.
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
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
Show cinema name, film title, date, and price for each record in schedule.
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
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
What are the title and director of the films without any schedule?
SELECT title , directed_by FROM film WHERE film_id NOT IN (SELECT film_id FROM schedule)
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
Show director with the largest number of show times in total.
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
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
Find the locations that have more than one movie theater with capacity above 300.
SELECT LOCATION FROM cinema WHERE capacity > 300 GROUP BY LOCATION HAVING count(*) > 1
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
In which locations are there more than one movie theater with capacity above 300?
SELECT LOCATION FROM cinema WHERE capacity > 300 GROUP BY LOCATION HAVING count(*) > 1
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
How many films have the word 'Dummy' in their titles?
SELECT count(*) FROM film WHERE title LIKE "%Dummy%"
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
cinema
Count the number of films whose title contains the word 'Dummy'.
SELECT count(*) FROM film WHERE title LIKE "%Dummy%"
CREATE TABLE "film" ( "Film_ID" int, "Rank_in_series" int, "Number_in_season" int, "Title" text, "Directed_by" text, "Original_air_date" text, "Production_code" text, PRIMARY KEY ("Film_ID") ) 3 rows from film table: Film_ID Rank_in_series Number_in_season Title Directed_by Original_air_date Production_code 1 26 1 The Case of the Mystery Weekend Bill Schreiner September 21–25, 1992 50021–50025 2 27 2 The Case of the Smart Dummy Bill Schreiner September 28–October 2, 1992 50231–50235 3 28 3 The Case: Off the Record Bill Schreiner October 5–9, 1992 50011–50015 CREATE TABLE "cinema" ( "Cinema_ID" int, "Name" text, "Openning_year" int, "Capacity" int, "Location" text, PRIMARY KEY ("Cinema_ID")) 3 rows from cinema table: Cinema_ID Name Openning_year Capacity Location 1 Codling 2010 1100 County Wicklow 2 Carrowleagh 2012 368 County Cork 3 Dublin Array 2015 364 County Dublin CREATE TABLE "schedule" ( "Cinema_ID" int, "Film_ID" int, "Date" text, "Show_times_per_day" int, "Price" float, PRIMARY KEY ("Cinema_ID","Film_ID"), FOREIGN KEY (`Film_ID`) REFERENCES `film`(`Film_ID`), FOREIGN KEY (`Cinema_ID`) REFERENCES `cinema`(`Cinema_ID`) ) 3 rows from schedule table: Cinema_ID Film_ID Date Show_times_per_day Price 1 1 21 May 5 12.99 1 2 21 May 3 12.99 1 3 21 Jun 2 8.99
products_for_hire
Are the customers holding coupons with amount 500 bad or good?
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
CREATE TABLE `Discount_Coupons` ( `coupon_id` INTEGER PRIMARY KEY, `date_issued` DATETIME, `coupon_amount` DECIMAL(19,4) ) 3 rows from Discount_Coupons table: coupon_id date_issued coupon_amount 1 2017-09-06 01:33:27 500.00 2 2018-02-20 09:40:56 686.25 3 2017-09-17 23:31:36 501.30 CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `coupon_id` INTEGER NOT NULL, `good_or_bad_customer` VARCHAR(4), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `gender_mf` VARCHAR(1), `date_became_customer` DATETIME, `date_last_hire` DATETIME, FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` ) ) 3 rows from Customers table: customer_id coupon_id good_or_bad_customer first_name last_name gender_mf date_became_customer date_last_hire 1 12 good Geovany Homenick 0 2017-10-20 12:13:17 2018-02-27 18:55:26 2 14 good Jailyn Gerlach 0 2015-04-06 21:18:37 2018-01-30 04:47:13 3 7 good Rosalee Kessler 0 2016-02-03 16:58:11 2018-03-04 21:30:23 CREATE TABLE `Bookings` ( `booking_id` INTEGER PRIMARY KEY , `customer_id` INTEGER NOT NULL, `booking_status_code` VARCHAR(10) NOT NULL, `returned_damaged_yn` VARCHAR(40), `booking_start_date` DATETIME, `booking_end_date` DATETIME, `count_hired` VARCHAR(40), `amount_payable` DECIMAL(19,4), `amount_of_discount` DECIMAL(19,4), `amount_outstanding` DECIMAL(19,4), `amount_of_refund` DECIMAL(19,4), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Bookings table: booking_id customer_id booking_status_code returned_damaged_yn booking_start_date booking_end_date count_hired amount_payable amount_of_discount amount_outstanding amount_of_refund 1 7 Provisional 1 2016-12-07 23:39:17 2018-02-01 16:39:13 298 214.39 71.45 28.22 179.14 2 15 Confirmed 1 2017-06-16 11:42:31 2018-02-19 21:53:31 331 386.92 83.82 57.62 183.68 3 3 Confirmed 1 2017-04-04 11:02:43 2018-02-01 09:30:50 729 351.32 49.26 66.01 135.94 CREATE TABLE `Products_for_Hire` ( `product_id` INTEGER PRIMARY KEY, `product_type_code` VARCHAR(15) NOT NULL, `daily_hire_cost` DECIMAL(19,4), `product_name` VARCHAR(80), `product_description` VARCHAR(255) ) 3 rows from Products_for_Hire table: product_id product_type_code daily_hire_cost product_name product_description 1 Cutlery 26.15 Book collection C Anna Karenina 2 Cutlery 15.62 Book collection B War and Peace 3 Cutlery 39.73 Book collection A The Great Gatsby CREATE TABLE `Payments` ( `payment_id` INTEGER PRIMARY KEY, `booking_id` INTEGER, `customer_id` INTEGER NOT NULL, `payment_type_code` VARCHAR(15) NOT NULL, `amount_paid_in_full_yn` VARCHAR(1), `payment_date` DATETIME, `amount_due` DECIMAL(19,4), `amount_paid` DECIMAL(19,4), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Payments table: payment_id booking_id customer_id payment_type_code amount_paid_in_full_yn payment_date amount_due amount_paid 1 6 15 Check 1 2018-03-09 16:28:00 369.52 206.27 2 9 12 Cash 1 2018-03-03 13:39:44 278.60 666.45 3 5 7 Credit Card 0 2018-03-22 15:00:23 840.06 135.70 CREATE TABLE `Products_Booked` ( `booking_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `returned_yn` VARCHAR(1), `returned_late_yn` VARCHAR(1), `booked_count` INTEGER, `booked_amount` FLOAT NULL, PRIMARY KEY (`booking_id`, `product_id`) FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from Products_Booked table: booking_id product_id returned_yn returned_late_yn booked_count booked_amount 4 1 1 1 5 309.73 14 1 1 0 3 102.76 13 3 1 0 4 151.68 CREATE TABLE `View_Product_Availability` ( `product_id` INTEGER NOT NULL, `booking_id` INTEGER NOT NULL, `status_date` DATETIME PRIMARY KEY, `available_yn` VARCHAR(1), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from View_Product_Availability table: product_id booking_id status_date available_yn 1 5 2018-03-18 05:25:55 1 2 5 2018-03-21 15:20:32 0 3 11 2018-03-25 10:20:15 1
products_for_hire
How many bookings did each customer make? List the customer id, first name, and the count.
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
CREATE TABLE `Discount_Coupons` ( `coupon_id` INTEGER PRIMARY KEY, `date_issued` DATETIME, `coupon_amount` DECIMAL(19,4) ) 3 rows from Discount_Coupons table: coupon_id date_issued coupon_amount 1 2017-09-06 01:33:27 500.00 2 2018-02-20 09:40:56 686.25 3 2017-09-17 23:31:36 501.30 CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `coupon_id` INTEGER NOT NULL, `good_or_bad_customer` VARCHAR(4), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `gender_mf` VARCHAR(1), `date_became_customer` DATETIME, `date_last_hire` DATETIME, FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` ) ) 3 rows from Customers table: customer_id coupon_id good_or_bad_customer first_name last_name gender_mf date_became_customer date_last_hire 1 12 good Geovany Homenick 0 2017-10-20 12:13:17 2018-02-27 18:55:26 2 14 good Jailyn Gerlach 0 2015-04-06 21:18:37 2018-01-30 04:47:13 3 7 good Rosalee Kessler 0 2016-02-03 16:58:11 2018-03-04 21:30:23 CREATE TABLE `Bookings` ( `booking_id` INTEGER PRIMARY KEY , `customer_id` INTEGER NOT NULL, `booking_status_code` VARCHAR(10) NOT NULL, `returned_damaged_yn` VARCHAR(40), `booking_start_date` DATETIME, `booking_end_date` DATETIME, `count_hired` VARCHAR(40), `amount_payable` DECIMAL(19,4), `amount_of_discount` DECIMAL(19,4), `amount_outstanding` DECIMAL(19,4), `amount_of_refund` DECIMAL(19,4), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Bookings table: booking_id customer_id booking_status_code returned_damaged_yn booking_start_date booking_end_date count_hired amount_payable amount_of_discount amount_outstanding amount_of_refund 1 7 Provisional 1 2016-12-07 23:39:17 2018-02-01 16:39:13 298 214.39 71.45 28.22 179.14 2 15 Confirmed 1 2017-06-16 11:42:31 2018-02-19 21:53:31 331 386.92 83.82 57.62 183.68 3 3 Confirmed 1 2017-04-04 11:02:43 2018-02-01 09:30:50 729 351.32 49.26 66.01 135.94 CREATE TABLE `Products_for_Hire` ( `product_id` INTEGER PRIMARY KEY, `product_type_code` VARCHAR(15) NOT NULL, `daily_hire_cost` DECIMAL(19,4), `product_name` VARCHAR(80), `product_description` VARCHAR(255) ) 3 rows from Products_for_Hire table: product_id product_type_code daily_hire_cost product_name product_description 1 Cutlery 26.15 Book collection C Anna Karenina 2 Cutlery 15.62 Book collection B War and Peace 3 Cutlery 39.73 Book collection A The Great Gatsby CREATE TABLE `Payments` ( `payment_id` INTEGER PRIMARY KEY, `booking_id` INTEGER, `customer_id` INTEGER NOT NULL, `payment_type_code` VARCHAR(15) NOT NULL, `amount_paid_in_full_yn` VARCHAR(1), `payment_date` DATETIME, `amount_due` DECIMAL(19,4), `amount_paid` DECIMAL(19,4), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Payments table: payment_id booking_id customer_id payment_type_code amount_paid_in_full_yn payment_date amount_due amount_paid 1 6 15 Check 1 2018-03-09 16:28:00 369.52 206.27 2 9 12 Cash 1 2018-03-03 13:39:44 278.60 666.45 3 5 7 Credit Card 0 2018-03-22 15:00:23 840.06 135.70 CREATE TABLE `Products_Booked` ( `booking_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `returned_yn` VARCHAR(1), `returned_late_yn` VARCHAR(1), `booked_count` INTEGER, `booked_amount` FLOAT NULL, PRIMARY KEY (`booking_id`, `product_id`) FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from Products_Booked table: booking_id product_id returned_yn returned_late_yn booked_count booked_amount 4 1 1 1 5 309.73 14 1 1 0 3 102.76 13 3 1 0 4 151.68 CREATE TABLE `View_Product_Availability` ( `product_id` INTEGER NOT NULL, `booking_id` INTEGER NOT NULL, `status_date` DATETIME PRIMARY KEY, `available_yn` VARCHAR(1), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from View_Product_Availability table: product_id booking_id status_date available_yn 1 5 2018-03-18 05:25:55 1 2 5 2018-03-21 15:20:32 0 3 11 2018-03-25 10:20:15 1
products_for_hire
What is the maximum total amount paid by a customer? List the customer id and amount.
SELECT customer_id , sum(amount_paid) FROM Payments GROUP BY customer_id ORDER BY sum(amount_paid) DESC LIMIT 1
CREATE TABLE `Discount_Coupons` ( `coupon_id` INTEGER PRIMARY KEY, `date_issued` DATETIME, `coupon_amount` DECIMAL(19,4) ) 3 rows from Discount_Coupons table: coupon_id date_issued coupon_amount 1 2017-09-06 01:33:27 500.00 2 2018-02-20 09:40:56 686.25 3 2017-09-17 23:31:36 501.30 CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `coupon_id` INTEGER NOT NULL, `good_or_bad_customer` VARCHAR(4), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `gender_mf` VARCHAR(1), `date_became_customer` DATETIME, `date_last_hire` DATETIME, FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` ) ) 3 rows from Customers table: customer_id coupon_id good_or_bad_customer first_name last_name gender_mf date_became_customer date_last_hire 1 12 good Geovany Homenick 0 2017-10-20 12:13:17 2018-02-27 18:55:26 2 14 good Jailyn Gerlach 0 2015-04-06 21:18:37 2018-01-30 04:47:13 3 7 good Rosalee Kessler 0 2016-02-03 16:58:11 2018-03-04 21:30:23 CREATE TABLE `Bookings` ( `booking_id` INTEGER PRIMARY KEY , `customer_id` INTEGER NOT NULL, `booking_status_code` VARCHAR(10) NOT NULL, `returned_damaged_yn` VARCHAR(40), `booking_start_date` DATETIME, `booking_end_date` DATETIME, `count_hired` VARCHAR(40), `amount_payable` DECIMAL(19,4), `amount_of_discount` DECIMAL(19,4), `amount_outstanding` DECIMAL(19,4), `amount_of_refund` DECIMAL(19,4), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Bookings table: booking_id customer_id booking_status_code returned_damaged_yn booking_start_date booking_end_date count_hired amount_payable amount_of_discount amount_outstanding amount_of_refund 1 7 Provisional 1 2016-12-07 23:39:17 2018-02-01 16:39:13 298 214.39 71.45 28.22 179.14 2 15 Confirmed 1 2017-06-16 11:42:31 2018-02-19 21:53:31 331 386.92 83.82 57.62 183.68 3 3 Confirmed 1 2017-04-04 11:02:43 2018-02-01 09:30:50 729 351.32 49.26 66.01 135.94 CREATE TABLE `Products_for_Hire` ( `product_id` INTEGER PRIMARY KEY, `product_type_code` VARCHAR(15) NOT NULL, `daily_hire_cost` DECIMAL(19,4), `product_name` VARCHAR(80), `product_description` VARCHAR(255) ) 3 rows from Products_for_Hire table: product_id product_type_code daily_hire_cost product_name product_description 1 Cutlery 26.15 Book collection C Anna Karenina 2 Cutlery 15.62 Book collection B War and Peace 3 Cutlery 39.73 Book collection A The Great Gatsby CREATE TABLE `Payments` ( `payment_id` INTEGER PRIMARY KEY, `booking_id` INTEGER, `customer_id` INTEGER NOT NULL, `payment_type_code` VARCHAR(15) NOT NULL, `amount_paid_in_full_yn` VARCHAR(1), `payment_date` DATETIME, `amount_due` DECIMAL(19,4), `amount_paid` DECIMAL(19,4), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Payments table: payment_id booking_id customer_id payment_type_code amount_paid_in_full_yn payment_date amount_due amount_paid 1 6 15 Check 1 2018-03-09 16:28:00 369.52 206.27 2 9 12 Cash 1 2018-03-03 13:39:44 278.60 666.45 3 5 7 Credit Card 0 2018-03-22 15:00:23 840.06 135.70 CREATE TABLE `Products_Booked` ( `booking_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `returned_yn` VARCHAR(1), `returned_late_yn` VARCHAR(1), `booked_count` INTEGER, `booked_amount` FLOAT NULL, PRIMARY KEY (`booking_id`, `product_id`) FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from Products_Booked table: booking_id product_id returned_yn returned_late_yn booked_count booked_amount 4 1 1 1 5 309.73 14 1 1 0 3 102.76 13 3 1 0 4 151.68 CREATE TABLE `View_Product_Availability` ( `product_id` INTEGER NOT NULL, `booking_id` INTEGER NOT NULL, `status_date` DATETIME PRIMARY KEY, `available_yn` VARCHAR(1), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from View_Product_Availability table: product_id booking_id status_date available_yn 1 5 2018-03-18 05:25:55 1 2 5 2018-03-21 15:20:32 0 3 11 2018-03-25 10:20:15 1
products_for_hire
What are the id and the amount of refund of the booking that incurred the most times of payments?
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
CREATE TABLE `Discount_Coupons` ( `coupon_id` INTEGER PRIMARY KEY, `date_issued` DATETIME, `coupon_amount` DECIMAL(19,4) ) 3 rows from Discount_Coupons table: coupon_id date_issued coupon_amount 1 2017-09-06 01:33:27 500.00 2 2018-02-20 09:40:56 686.25 3 2017-09-17 23:31:36 501.30 CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `coupon_id` INTEGER NOT NULL, `good_or_bad_customer` VARCHAR(4), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `gender_mf` VARCHAR(1), `date_became_customer` DATETIME, `date_last_hire` DATETIME, FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` ) ) 3 rows from Customers table: customer_id coupon_id good_or_bad_customer first_name last_name gender_mf date_became_customer date_last_hire 1 12 good Geovany Homenick 0 2017-10-20 12:13:17 2018-02-27 18:55:26 2 14 good Jailyn Gerlach 0 2015-04-06 21:18:37 2018-01-30 04:47:13 3 7 good Rosalee Kessler 0 2016-02-03 16:58:11 2018-03-04 21:30:23 CREATE TABLE `Bookings` ( `booking_id` INTEGER PRIMARY KEY , `customer_id` INTEGER NOT NULL, `booking_status_code` VARCHAR(10) NOT NULL, `returned_damaged_yn` VARCHAR(40), `booking_start_date` DATETIME, `booking_end_date` DATETIME, `count_hired` VARCHAR(40), `amount_payable` DECIMAL(19,4), `amount_of_discount` DECIMAL(19,4), `amount_outstanding` DECIMAL(19,4), `amount_of_refund` DECIMAL(19,4), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Bookings table: booking_id customer_id booking_status_code returned_damaged_yn booking_start_date booking_end_date count_hired amount_payable amount_of_discount amount_outstanding amount_of_refund 1 7 Provisional 1 2016-12-07 23:39:17 2018-02-01 16:39:13 298 214.39 71.45 28.22 179.14 2 15 Confirmed 1 2017-06-16 11:42:31 2018-02-19 21:53:31 331 386.92 83.82 57.62 183.68 3 3 Confirmed 1 2017-04-04 11:02:43 2018-02-01 09:30:50 729 351.32 49.26 66.01 135.94 CREATE TABLE `Products_for_Hire` ( `product_id` INTEGER PRIMARY KEY, `product_type_code` VARCHAR(15) NOT NULL, `daily_hire_cost` DECIMAL(19,4), `product_name` VARCHAR(80), `product_description` VARCHAR(255) ) 3 rows from Products_for_Hire table: product_id product_type_code daily_hire_cost product_name product_description 1 Cutlery 26.15 Book collection C Anna Karenina 2 Cutlery 15.62 Book collection B War and Peace 3 Cutlery 39.73 Book collection A The Great Gatsby CREATE TABLE `Payments` ( `payment_id` INTEGER PRIMARY KEY, `booking_id` INTEGER, `customer_id` INTEGER NOT NULL, `payment_type_code` VARCHAR(15) NOT NULL, `amount_paid_in_full_yn` VARCHAR(1), `payment_date` DATETIME, `amount_due` DECIMAL(19,4), `amount_paid` DECIMAL(19,4), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Payments table: payment_id booking_id customer_id payment_type_code amount_paid_in_full_yn payment_date amount_due amount_paid 1 6 15 Check 1 2018-03-09 16:28:00 369.52 206.27 2 9 12 Cash 1 2018-03-03 13:39:44 278.60 666.45 3 5 7 Credit Card 0 2018-03-22 15:00:23 840.06 135.70 CREATE TABLE `Products_Booked` ( `booking_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `returned_yn` VARCHAR(1), `returned_late_yn` VARCHAR(1), `booked_count` INTEGER, `booked_amount` FLOAT NULL, PRIMARY KEY (`booking_id`, `product_id`) FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from Products_Booked table: booking_id product_id returned_yn returned_late_yn booked_count booked_amount 4 1 1 1 5 309.73 14 1 1 0 3 102.76 13 3 1 0 4 151.68 CREATE TABLE `View_Product_Availability` ( `product_id` INTEGER NOT NULL, `booking_id` INTEGER NOT NULL, `status_date` DATETIME PRIMARY KEY, `available_yn` VARCHAR(1), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from View_Product_Availability table: product_id booking_id status_date available_yn 1 5 2018-03-18 05:25:55 1 2 5 2018-03-21 15:20:32 0 3 11 2018-03-25 10:20:15 1
products_for_hire
What is the id of the product that is booked for 3 times?
SELECT product_id FROM products_booked GROUP BY product_id HAVING count(*) = 3
CREATE TABLE `Discount_Coupons` ( `coupon_id` INTEGER PRIMARY KEY, `date_issued` DATETIME, `coupon_amount` DECIMAL(19,4) ) 3 rows from Discount_Coupons table: coupon_id date_issued coupon_amount 1 2017-09-06 01:33:27 500.00 2 2018-02-20 09:40:56 686.25 3 2017-09-17 23:31:36 501.30 CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `coupon_id` INTEGER NOT NULL, `good_or_bad_customer` VARCHAR(4), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `gender_mf` VARCHAR(1), `date_became_customer` DATETIME, `date_last_hire` DATETIME, FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` ) ) 3 rows from Customers table: customer_id coupon_id good_or_bad_customer first_name last_name gender_mf date_became_customer date_last_hire 1 12 good Geovany Homenick 0 2017-10-20 12:13:17 2018-02-27 18:55:26 2 14 good Jailyn Gerlach 0 2015-04-06 21:18:37 2018-01-30 04:47:13 3 7 good Rosalee Kessler 0 2016-02-03 16:58:11 2018-03-04 21:30:23 CREATE TABLE `Bookings` ( `booking_id` INTEGER PRIMARY KEY , `customer_id` INTEGER NOT NULL, `booking_status_code` VARCHAR(10) NOT NULL, `returned_damaged_yn` VARCHAR(40), `booking_start_date` DATETIME, `booking_end_date` DATETIME, `count_hired` VARCHAR(40), `amount_payable` DECIMAL(19,4), `amount_of_discount` DECIMAL(19,4), `amount_outstanding` DECIMAL(19,4), `amount_of_refund` DECIMAL(19,4), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Bookings table: booking_id customer_id booking_status_code returned_damaged_yn booking_start_date booking_end_date count_hired amount_payable amount_of_discount amount_outstanding amount_of_refund 1 7 Provisional 1 2016-12-07 23:39:17 2018-02-01 16:39:13 298 214.39 71.45 28.22 179.14 2 15 Confirmed 1 2017-06-16 11:42:31 2018-02-19 21:53:31 331 386.92 83.82 57.62 183.68 3 3 Confirmed 1 2017-04-04 11:02:43 2018-02-01 09:30:50 729 351.32 49.26 66.01 135.94 CREATE TABLE `Products_for_Hire` ( `product_id` INTEGER PRIMARY KEY, `product_type_code` VARCHAR(15) NOT NULL, `daily_hire_cost` DECIMAL(19,4), `product_name` VARCHAR(80), `product_description` VARCHAR(255) ) 3 rows from Products_for_Hire table: product_id product_type_code daily_hire_cost product_name product_description 1 Cutlery 26.15 Book collection C Anna Karenina 2 Cutlery 15.62 Book collection B War and Peace 3 Cutlery 39.73 Book collection A The Great Gatsby CREATE TABLE `Payments` ( `payment_id` INTEGER PRIMARY KEY, `booking_id` INTEGER, `customer_id` INTEGER NOT NULL, `payment_type_code` VARCHAR(15) NOT NULL, `amount_paid_in_full_yn` VARCHAR(1), `payment_date` DATETIME, `amount_due` DECIMAL(19,4), `amount_paid` DECIMAL(19,4), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Payments table: payment_id booking_id customer_id payment_type_code amount_paid_in_full_yn payment_date amount_due amount_paid 1 6 15 Check 1 2018-03-09 16:28:00 369.52 206.27 2 9 12 Cash 1 2018-03-03 13:39:44 278.60 666.45 3 5 7 Credit Card 0 2018-03-22 15:00:23 840.06 135.70 CREATE TABLE `Products_Booked` ( `booking_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `returned_yn` VARCHAR(1), `returned_late_yn` VARCHAR(1), `booked_count` INTEGER, `booked_amount` FLOAT NULL, PRIMARY KEY (`booking_id`, `product_id`) FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from Products_Booked table: booking_id product_id returned_yn returned_late_yn booked_count booked_amount 4 1 1 1 5 309.73 14 1 1 0 3 102.76 13 3 1 0 4 151.68 CREATE TABLE `View_Product_Availability` ( `product_id` INTEGER NOT NULL, `booking_id` INTEGER NOT NULL, `status_date` DATETIME PRIMARY KEY, `available_yn` VARCHAR(1), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from View_Product_Availability table: product_id booking_id status_date available_yn 1 5 2018-03-18 05:25:55 1 2 5 2018-03-21 15:20:32 0 3 11 2018-03-25 10:20:15 1
products_for_hire
What is the product description of the product booked with an amount of 102.76?
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
CREATE TABLE `Discount_Coupons` ( `coupon_id` INTEGER PRIMARY KEY, `date_issued` DATETIME, `coupon_amount` DECIMAL(19,4) ) 3 rows from Discount_Coupons table: coupon_id date_issued coupon_amount 1 2017-09-06 01:33:27 500.00 2 2018-02-20 09:40:56 686.25 3 2017-09-17 23:31:36 501.30 CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `coupon_id` INTEGER NOT NULL, `good_or_bad_customer` VARCHAR(4), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `gender_mf` VARCHAR(1), `date_became_customer` DATETIME, `date_last_hire` DATETIME, FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` ) ) 3 rows from Customers table: customer_id coupon_id good_or_bad_customer first_name last_name gender_mf date_became_customer date_last_hire 1 12 good Geovany Homenick 0 2017-10-20 12:13:17 2018-02-27 18:55:26 2 14 good Jailyn Gerlach 0 2015-04-06 21:18:37 2018-01-30 04:47:13 3 7 good Rosalee Kessler 0 2016-02-03 16:58:11 2018-03-04 21:30:23 CREATE TABLE `Bookings` ( `booking_id` INTEGER PRIMARY KEY , `customer_id` INTEGER NOT NULL, `booking_status_code` VARCHAR(10) NOT NULL, `returned_damaged_yn` VARCHAR(40), `booking_start_date` DATETIME, `booking_end_date` DATETIME, `count_hired` VARCHAR(40), `amount_payable` DECIMAL(19,4), `amount_of_discount` DECIMAL(19,4), `amount_outstanding` DECIMAL(19,4), `amount_of_refund` DECIMAL(19,4), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Bookings table: booking_id customer_id booking_status_code returned_damaged_yn booking_start_date booking_end_date count_hired amount_payable amount_of_discount amount_outstanding amount_of_refund 1 7 Provisional 1 2016-12-07 23:39:17 2018-02-01 16:39:13 298 214.39 71.45 28.22 179.14 2 15 Confirmed 1 2017-06-16 11:42:31 2018-02-19 21:53:31 331 386.92 83.82 57.62 183.68 3 3 Confirmed 1 2017-04-04 11:02:43 2018-02-01 09:30:50 729 351.32 49.26 66.01 135.94 CREATE TABLE `Products_for_Hire` ( `product_id` INTEGER PRIMARY KEY, `product_type_code` VARCHAR(15) NOT NULL, `daily_hire_cost` DECIMAL(19,4), `product_name` VARCHAR(80), `product_description` VARCHAR(255) ) 3 rows from Products_for_Hire table: product_id product_type_code daily_hire_cost product_name product_description 1 Cutlery 26.15 Book collection C Anna Karenina 2 Cutlery 15.62 Book collection B War and Peace 3 Cutlery 39.73 Book collection A The Great Gatsby CREATE TABLE `Payments` ( `payment_id` INTEGER PRIMARY KEY, `booking_id` INTEGER, `customer_id` INTEGER NOT NULL, `payment_type_code` VARCHAR(15) NOT NULL, `amount_paid_in_full_yn` VARCHAR(1), `payment_date` DATETIME, `amount_due` DECIMAL(19,4), `amount_paid` DECIMAL(19,4), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Payments table: payment_id booking_id customer_id payment_type_code amount_paid_in_full_yn payment_date amount_due amount_paid 1 6 15 Check 1 2018-03-09 16:28:00 369.52 206.27 2 9 12 Cash 1 2018-03-03 13:39:44 278.60 666.45 3 5 7 Credit Card 0 2018-03-22 15:00:23 840.06 135.70 CREATE TABLE `Products_Booked` ( `booking_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `returned_yn` VARCHAR(1), `returned_late_yn` VARCHAR(1), `booked_count` INTEGER, `booked_amount` FLOAT NULL, PRIMARY KEY (`booking_id`, `product_id`) FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from Products_Booked table: booking_id product_id returned_yn returned_late_yn booked_count booked_amount 4 1 1 1 5 309.73 14 1 1 0 3 102.76 13 3 1 0 4 151.68 CREATE TABLE `View_Product_Availability` ( `product_id` INTEGER NOT NULL, `booking_id` INTEGER NOT NULL, `status_date` DATETIME PRIMARY KEY, `available_yn` VARCHAR(1), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from View_Product_Availability table: product_id booking_id status_date available_yn 1 5 2018-03-18 05:25:55 1 2 5 2018-03-21 15:20:32 0 3 11 2018-03-25 10:20:15 1
products_for_hire
What are the start date and end date of the booking that has booked the product named 'Book collection A'?
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'
CREATE TABLE `Discount_Coupons` ( `coupon_id` INTEGER PRIMARY KEY, `date_issued` DATETIME, `coupon_amount` DECIMAL(19,4) ) 3 rows from Discount_Coupons table: coupon_id date_issued coupon_amount 1 2017-09-06 01:33:27 500.00 2 2018-02-20 09:40:56 686.25 3 2017-09-17 23:31:36 501.30 CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `coupon_id` INTEGER NOT NULL, `good_or_bad_customer` VARCHAR(4), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `gender_mf` VARCHAR(1), `date_became_customer` DATETIME, `date_last_hire` DATETIME, FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` ) ) 3 rows from Customers table: customer_id coupon_id good_or_bad_customer first_name last_name gender_mf date_became_customer date_last_hire 1 12 good Geovany Homenick 0 2017-10-20 12:13:17 2018-02-27 18:55:26 2 14 good Jailyn Gerlach 0 2015-04-06 21:18:37 2018-01-30 04:47:13 3 7 good Rosalee Kessler 0 2016-02-03 16:58:11 2018-03-04 21:30:23 CREATE TABLE `Bookings` ( `booking_id` INTEGER PRIMARY KEY , `customer_id` INTEGER NOT NULL, `booking_status_code` VARCHAR(10) NOT NULL, `returned_damaged_yn` VARCHAR(40), `booking_start_date` DATETIME, `booking_end_date` DATETIME, `count_hired` VARCHAR(40), `amount_payable` DECIMAL(19,4), `amount_of_discount` DECIMAL(19,4), `amount_outstanding` DECIMAL(19,4), `amount_of_refund` DECIMAL(19,4), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Bookings table: booking_id customer_id booking_status_code returned_damaged_yn booking_start_date booking_end_date count_hired amount_payable amount_of_discount amount_outstanding amount_of_refund 1 7 Provisional 1 2016-12-07 23:39:17 2018-02-01 16:39:13 298 214.39 71.45 28.22 179.14 2 15 Confirmed 1 2017-06-16 11:42:31 2018-02-19 21:53:31 331 386.92 83.82 57.62 183.68 3 3 Confirmed 1 2017-04-04 11:02:43 2018-02-01 09:30:50 729 351.32 49.26 66.01 135.94 CREATE TABLE `Products_for_Hire` ( `product_id` INTEGER PRIMARY KEY, `product_type_code` VARCHAR(15) NOT NULL, `daily_hire_cost` DECIMAL(19,4), `product_name` VARCHAR(80), `product_description` VARCHAR(255) ) 3 rows from Products_for_Hire table: product_id product_type_code daily_hire_cost product_name product_description 1 Cutlery 26.15 Book collection C Anna Karenina 2 Cutlery 15.62 Book collection B War and Peace 3 Cutlery 39.73 Book collection A The Great Gatsby CREATE TABLE `Payments` ( `payment_id` INTEGER PRIMARY KEY, `booking_id` INTEGER, `customer_id` INTEGER NOT NULL, `payment_type_code` VARCHAR(15) NOT NULL, `amount_paid_in_full_yn` VARCHAR(1), `payment_date` DATETIME, `amount_due` DECIMAL(19,4), `amount_paid` DECIMAL(19,4), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Payments table: payment_id booking_id customer_id payment_type_code amount_paid_in_full_yn payment_date amount_due amount_paid 1 6 15 Check 1 2018-03-09 16:28:00 369.52 206.27 2 9 12 Cash 1 2018-03-03 13:39:44 278.60 666.45 3 5 7 Credit Card 0 2018-03-22 15:00:23 840.06 135.70 CREATE TABLE `Products_Booked` ( `booking_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `returned_yn` VARCHAR(1), `returned_late_yn` VARCHAR(1), `booked_count` INTEGER, `booked_amount` FLOAT NULL, PRIMARY KEY (`booking_id`, `product_id`) FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from Products_Booked table: booking_id product_id returned_yn returned_late_yn booked_count booked_amount 4 1 1 1 5 309.73 14 1 1 0 3 102.76 13 3 1 0 4 151.68 CREATE TABLE `View_Product_Availability` ( `product_id` INTEGER NOT NULL, `booking_id` INTEGER NOT NULL, `status_date` DATETIME PRIMARY KEY, `available_yn` VARCHAR(1), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from View_Product_Availability table: product_id booking_id status_date available_yn 1 5 2018-03-18 05:25:55 1 2 5 2018-03-21 15:20:32 0 3 11 2018-03-25 10:20:15 1
products_for_hire
What are the names of products whose availability equals to 1?
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
CREATE TABLE `Discount_Coupons` ( `coupon_id` INTEGER PRIMARY KEY, `date_issued` DATETIME, `coupon_amount` DECIMAL(19,4) ) 3 rows from Discount_Coupons table: coupon_id date_issued coupon_amount 1 2017-09-06 01:33:27 500.00 2 2018-02-20 09:40:56 686.25 3 2017-09-17 23:31:36 501.30 CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `coupon_id` INTEGER NOT NULL, `good_or_bad_customer` VARCHAR(4), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `gender_mf` VARCHAR(1), `date_became_customer` DATETIME, `date_last_hire` DATETIME, FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` ) ) 3 rows from Customers table: customer_id coupon_id good_or_bad_customer first_name last_name gender_mf date_became_customer date_last_hire 1 12 good Geovany Homenick 0 2017-10-20 12:13:17 2018-02-27 18:55:26 2 14 good Jailyn Gerlach 0 2015-04-06 21:18:37 2018-01-30 04:47:13 3 7 good Rosalee Kessler 0 2016-02-03 16:58:11 2018-03-04 21:30:23 CREATE TABLE `Bookings` ( `booking_id` INTEGER PRIMARY KEY , `customer_id` INTEGER NOT NULL, `booking_status_code` VARCHAR(10) NOT NULL, `returned_damaged_yn` VARCHAR(40), `booking_start_date` DATETIME, `booking_end_date` DATETIME, `count_hired` VARCHAR(40), `amount_payable` DECIMAL(19,4), `amount_of_discount` DECIMAL(19,4), `amount_outstanding` DECIMAL(19,4), `amount_of_refund` DECIMAL(19,4), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Bookings table: booking_id customer_id booking_status_code returned_damaged_yn booking_start_date booking_end_date count_hired amount_payable amount_of_discount amount_outstanding amount_of_refund 1 7 Provisional 1 2016-12-07 23:39:17 2018-02-01 16:39:13 298 214.39 71.45 28.22 179.14 2 15 Confirmed 1 2017-06-16 11:42:31 2018-02-19 21:53:31 331 386.92 83.82 57.62 183.68 3 3 Confirmed 1 2017-04-04 11:02:43 2018-02-01 09:30:50 729 351.32 49.26 66.01 135.94 CREATE TABLE `Products_for_Hire` ( `product_id` INTEGER PRIMARY KEY, `product_type_code` VARCHAR(15) NOT NULL, `daily_hire_cost` DECIMAL(19,4), `product_name` VARCHAR(80), `product_description` VARCHAR(255) ) 3 rows from Products_for_Hire table: product_id product_type_code daily_hire_cost product_name product_description 1 Cutlery 26.15 Book collection C Anna Karenina 2 Cutlery 15.62 Book collection B War and Peace 3 Cutlery 39.73 Book collection A The Great Gatsby CREATE TABLE `Payments` ( `payment_id` INTEGER PRIMARY KEY, `booking_id` INTEGER, `customer_id` INTEGER NOT NULL, `payment_type_code` VARCHAR(15) NOT NULL, `amount_paid_in_full_yn` VARCHAR(1), `payment_date` DATETIME, `amount_due` DECIMAL(19,4), `amount_paid` DECIMAL(19,4), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Payments table: payment_id booking_id customer_id payment_type_code amount_paid_in_full_yn payment_date amount_due amount_paid 1 6 15 Check 1 2018-03-09 16:28:00 369.52 206.27 2 9 12 Cash 1 2018-03-03 13:39:44 278.60 666.45 3 5 7 Credit Card 0 2018-03-22 15:00:23 840.06 135.70 CREATE TABLE `Products_Booked` ( `booking_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `returned_yn` VARCHAR(1), `returned_late_yn` VARCHAR(1), `booked_count` INTEGER, `booked_amount` FLOAT NULL, PRIMARY KEY (`booking_id`, `product_id`) FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from Products_Booked table: booking_id product_id returned_yn returned_late_yn booked_count booked_amount 4 1 1 1 5 309.73 14 1 1 0 3 102.76 13 3 1 0 4 151.68 CREATE TABLE `View_Product_Availability` ( `product_id` INTEGER NOT NULL, `booking_id` INTEGER NOT NULL, `status_date` DATETIME PRIMARY KEY, `available_yn` VARCHAR(1), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from View_Product_Availability table: product_id booking_id status_date available_yn 1 5 2018-03-18 05:25:55 1 2 5 2018-03-21 15:20:32 0 3 11 2018-03-25 10:20:15 1
products_for_hire
How many different product types are there?
SELECT count(DISTINCT product_type_code) FROM products_for_hire
CREATE TABLE `Discount_Coupons` ( `coupon_id` INTEGER PRIMARY KEY, `date_issued` DATETIME, `coupon_amount` DECIMAL(19,4) ) 3 rows from Discount_Coupons table: coupon_id date_issued coupon_amount 1 2017-09-06 01:33:27 500.00 2 2018-02-20 09:40:56 686.25 3 2017-09-17 23:31:36 501.30 CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `coupon_id` INTEGER NOT NULL, `good_or_bad_customer` VARCHAR(4), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `gender_mf` VARCHAR(1), `date_became_customer` DATETIME, `date_last_hire` DATETIME, FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` ) ) 3 rows from Customers table: customer_id coupon_id good_or_bad_customer first_name last_name gender_mf date_became_customer date_last_hire 1 12 good Geovany Homenick 0 2017-10-20 12:13:17 2018-02-27 18:55:26 2 14 good Jailyn Gerlach 0 2015-04-06 21:18:37 2018-01-30 04:47:13 3 7 good Rosalee Kessler 0 2016-02-03 16:58:11 2018-03-04 21:30:23 CREATE TABLE `Bookings` ( `booking_id` INTEGER PRIMARY KEY , `customer_id` INTEGER NOT NULL, `booking_status_code` VARCHAR(10) NOT NULL, `returned_damaged_yn` VARCHAR(40), `booking_start_date` DATETIME, `booking_end_date` DATETIME, `count_hired` VARCHAR(40), `amount_payable` DECIMAL(19,4), `amount_of_discount` DECIMAL(19,4), `amount_outstanding` DECIMAL(19,4), `amount_of_refund` DECIMAL(19,4), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Bookings table: booking_id customer_id booking_status_code returned_damaged_yn booking_start_date booking_end_date count_hired amount_payable amount_of_discount amount_outstanding amount_of_refund 1 7 Provisional 1 2016-12-07 23:39:17 2018-02-01 16:39:13 298 214.39 71.45 28.22 179.14 2 15 Confirmed 1 2017-06-16 11:42:31 2018-02-19 21:53:31 331 386.92 83.82 57.62 183.68 3 3 Confirmed 1 2017-04-04 11:02:43 2018-02-01 09:30:50 729 351.32 49.26 66.01 135.94 CREATE TABLE `Products_for_Hire` ( `product_id` INTEGER PRIMARY KEY, `product_type_code` VARCHAR(15) NOT NULL, `daily_hire_cost` DECIMAL(19,4), `product_name` VARCHAR(80), `product_description` VARCHAR(255) ) 3 rows from Products_for_Hire table: product_id product_type_code daily_hire_cost product_name product_description 1 Cutlery 26.15 Book collection C Anna Karenina 2 Cutlery 15.62 Book collection B War and Peace 3 Cutlery 39.73 Book collection A The Great Gatsby CREATE TABLE `Payments` ( `payment_id` INTEGER PRIMARY KEY, `booking_id` INTEGER, `customer_id` INTEGER NOT NULL, `payment_type_code` VARCHAR(15) NOT NULL, `amount_paid_in_full_yn` VARCHAR(1), `payment_date` DATETIME, `amount_due` DECIMAL(19,4), `amount_paid` DECIMAL(19,4), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Payments table: payment_id booking_id customer_id payment_type_code amount_paid_in_full_yn payment_date amount_due amount_paid 1 6 15 Check 1 2018-03-09 16:28:00 369.52 206.27 2 9 12 Cash 1 2018-03-03 13:39:44 278.60 666.45 3 5 7 Credit Card 0 2018-03-22 15:00:23 840.06 135.70 CREATE TABLE `Products_Booked` ( `booking_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `returned_yn` VARCHAR(1), `returned_late_yn` VARCHAR(1), `booked_count` INTEGER, `booked_amount` FLOAT NULL, PRIMARY KEY (`booking_id`, `product_id`) FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from Products_Booked table: booking_id product_id returned_yn returned_late_yn booked_count booked_amount 4 1 1 1 5 309.73 14 1 1 0 3 102.76 13 3 1 0 4 151.68 CREATE TABLE `View_Product_Availability` ( `product_id` INTEGER NOT NULL, `booking_id` INTEGER NOT NULL, `status_date` DATETIME PRIMARY KEY, `available_yn` VARCHAR(1), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from View_Product_Availability table: product_id booking_id status_date available_yn 1 5 2018-03-18 05:25:55 1 2 5 2018-03-21 15:20:32 0 3 11 2018-03-25 10:20:15 1
products_for_hire
What are the first name, last name, and gender of all the good customers? Order by their last name.
SELECT first_name , last_name , gender_mf FROM customers WHERE good_or_bad_customer = 'good' ORDER BY last_name
CREATE TABLE `Discount_Coupons` ( `coupon_id` INTEGER PRIMARY KEY, `date_issued` DATETIME, `coupon_amount` DECIMAL(19,4) ) 3 rows from Discount_Coupons table: coupon_id date_issued coupon_amount 1 2017-09-06 01:33:27 500.00 2 2018-02-20 09:40:56 686.25 3 2017-09-17 23:31:36 501.30 CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `coupon_id` INTEGER NOT NULL, `good_or_bad_customer` VARCHAR(4), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `gender_mf` VARCHAR(1), `date_became_customer` DATETIME, `date_last_hire` DATETIME, FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` ) ) 3 rows from Customers table: customer_id coupon_id good_or_bad_customer first_name last_name gender_mf date_became_customer date_last_hire 1 12 good Geovany Homenick 0 2017-10-20 12:13:17 2018-02-27 18:55:26 2 14 good Jailyn Gerlach 0 2015-04-06 21:18:37 2018-01-30 04:47:13 3 7 good Rosalee Kessler 0 2016-02-03 16:58:11 2018-03-04 21:30:23 CREATE TABLE `Bookings` ( `booking_id` INTEGER PRIMARY KEY , `customer_id` INTEGER NOT NULL, `booking_status_code` VARCHAR(10) NOT NULL, `returned_damaged_yn` VARCHAR(40), `booking_start_date` DATETIME, `booking_end_date` DATETIME, `count_hired` VARCHAR(40), `amount_payable` DECIMAL(19,4), `amount_of_discount` DECIMAL(19,4), `amount_outstanding` DECIMAL(19,4), `amount_of_refund` DECIMAL(19,4), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Bookings table: booking_id customer_id booking_status_code returned_damaged_yn booking_start_date booking_end_date count_hired amount_payable amount_of_discount amount_outstanding amount_of_refund 1 7 Provisional 1 2016-12-07 23:39:17 2018-02-01 16:39:13 298 214.39 71.45 28.22 179.14 2 15 Confirmed 1 2017-06-16 11:42:31 2018-02-19 21:53:31 331 386.92 83.82 57.62 183.68 3 3 Confirmed 1 2017-04-04 11:02:43 2018-02-01 09:30:50 729 351.32 49.26 66.01 135.94 CREATE TABLE `Products_for_Hire` ( `product_id` INTEGER PRIMARY KEY, `product_type_code` VARCHAR(15) NOT NULL, `daily_hire_cost` DECIMAL(19,4), `product_name` VARCHAR(80), `product_description` VARCHAR(255) ) 3 rows from Products_for_Hire table: product_id product_type_code daily_hire_cost product_name product_description 1 Cutlery 26.15 Book collection C Anna Karenina 2 Cutlery 15.62 Book collection B War and Peace 3 Cutlery 39.73 Book collection A The Great Gatsby CREATE TABLE `Payments` ( `payment_id` INTEGER PRIMARY KEY, `booking_id` INTEGER, `customer_id` INTEGER NOT NULL, `payment_type_code` VARCHAR(15) NOT NULL, `amount_paid_in_full_yn` VARCHAR(1), `payment_date` DATETIME, `amount_due` DECIMAL(19,4), `amount_paid` DECIMAL(19,4), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Payments table: payment_id booking_id customer_id payment_type_code amount_paid_in_full_yn payment_date amount_due amount_paid 1 6 15 Check 1 2018-03-09 16:28:00 369.52 206.27 2 9 12 Cash 1 2018-03-03 13:39:44 278.60 666.45 3 5 7 Credit Card 0 2018-03-22 15:00:23 840.06 135.70 CREATE TABLE `Products_Booked` ( `booking_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `returned_yn` VARCHAR(1), `returned_late_yn` VARCHAR(1), `booked_count` INTEGER, `booked_amount` FLOAT NULL, PRIMARY KEY (`booking_id`, `product_id`) FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from Products_Booked table: booking_id product_id returned_yn returned_late_yn booked_count booked_amount 4 1 1 1 5 309.73 14 1 1 0 3 102.76 13 3 1 0 4 151.68 CREATE TABLE `View_Product_Availability` ( `product_id` INTEGER NOT NULL, `booking_id` INTEGER NOT NULL, `status_date` DATETIME PRIMARY KEY, `available_yn` VARCHAR(1), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from View_Product_Availability table: product_id booking_id status_date available_yn 1 5 2018-03-18 05:25:55 1 2 5 2018-03-21 15:20:32 0 3 11 2018-03-25 10:20:15 1
products_for_hire
What is the average amount due for all the payments?
SELECT avg(amount_due) FROM payments
CREATE TABLE `Discount_Coupons` ( `coupon_id` INTEGER PRIMARY KEY, `date_issued` DATETIME, `coupon_amount` DECIMAL(19,4) ) 3 rows from Discount_Coupons table: coupon_id date_issued coupon_amount 1 2017-09-06 01:33:27 500.00 2 2018-02-20 09:40:56 686.25 3 2017-09-17 23:31:36 501.30 CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `coupon_id` INTEGER NOT NULL, `good_or_bad_customer` VARCHAR(4), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `gender_mf` VARCHAR(1), `date_became_customer` DATETIME, `date_last_hire` DATETIME, FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` ) ) 3 rows from Customers table: customer_id coupon_id good_or_bad_customer first_name last_name gender_mf date_became_customer date_last_hire 1 12 good Geovany Homenick 0 2017-10-20 12:13:17 2018-02-27 18:55:26 2 14 good Jailyn Gerlach 0 2015-04-06 21:18:37 2018-01-30 04:47:13 3 7 good Rosalee Kessler 0 2016-02-03 16:58:11 2018-03-04 21:30:23 CREATE TABLE `Bookings` ( `booking_id` INTEGER PRIMARY KEY , `customer_id` INTEGER NOT NULL, `booking_status_code` VARCHAR(10) NOT NULL, `returned_damaged_yn` VARCHAR(40), `booking_start_date` DATETIME, `booking_end_date` DATETIME, `count_hired` VARCHAR(40), `amount_payable` DECIMAL(19,4), `amount_of_discount` DECIMAL(19,4), `amount_outstanding` DECIMAL(19,4), `amount_of_refund` DECIMAL(19,4), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Bookings table: booking_id customer_id booking_status_code returned_damaged_yn booking_start_date booking_end_date count_hired amount_payable amount_of_discount amount_outstanding amount_of_refund 1 7 Provisional 1 2016-12-07 23:39:17 2018-02-01 16:39:13 298 214.39 71.45 28.22 179.14 2 15 Confirmed 1 2017-06-16 11:42:31 2018-02-19 21:53:31 331 386.92 83.82 57.62 183.68 3 3 Confirmed 1 2017-04-04 11:02:43 2018-02-01 09:30:50 729 351.32 49.26 66.01 135.94 CREATE TABLE `Products_for_Hire` ( `product_id` INTEGER PRIMARY KEY, `product_type_code` VARCHAR(15) NOT NULL, `daily_hire_cost` DECIMAL(19,4), `product_name` VARCHAR(80), `product_description` VARCHAR(255) ) 3 rows from Products_for_Hire table: product_id product_type_code daily_hire_cost product_name product_description 1 Cutlery 26.15 Book collection C Anna Karenina 2 Cutlery 15.62 Book collection B War and Peace 3 Cutlery 39.73 Book collection A The Great Gatsby CREATE TABLE `Payments` ( `payment_id` INTEGER PRIMARY KEY, `booking_id` INTEGER, `customer_id` INTEGER NOT NULL, `payment_type_code` VARCHAR(15) NOT NULL, `amount_paid_in_full_yn` VARCHAR(1), `payment_date` DATETIME, `amount_due` DECIMAL(19,4), `amount_paid` DECIMAL(19,4), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Payments table: payment_id booking_id customer_id payment_type_code amount_paid_in_full_yn payment_date amount_due amount_paid 1 6 15 Check 1 2018-03-09 16:28:00 369.52 206.27 2 9 12 Cash 1 2018-03-03 13:39:44 278.60 666.45 3 5 7 Credit Card 0 2018-03-22 15:00:23 840.06 135.70 CREATE TABLE `Products_Booked` ( `booking_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `returned_yn` VARCHAR(1), `returned_late_yn` VARCHAR(1), `booked_count` INTEGER, `booked_amount` FLOAT NULL, PRIMARY KEY (`booking_id`, `product_id`) FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from Products_Booked table: booking_id product_id returned_yn returned_late_yn booked_count booked_amount 4 1 1 1 5 309.73 14 1 1 0 3 102.76 13 3 1 0 4 151.68 CREATE TABLE `View_Product_Availability` ( `product_id` INTEGER NOT NULL, `booking_id` INTEGER NOT NULL, `status_date` DATETIME PRIMARY KEY, `available_yn` VARCHAR(1), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from View_Product_Availability table: product_id booking_id status_date available_yn 1 5 2018-03-18 05:25:55 1 2 5 2018-03-21 15:20:32 0 3 11 2018-03-25 10:20:15 1
products_for_hire
What are the maximum, minimum, and average booked count for the products booked?
SELECT max(booked_count) , min(booked_count) , avg(booked_count) FROM products_booked
CREATE TABLE `Discount_Coupons` ( `coupon_id` INTEGER PRIMARY KEY, `date_issued` DATETIME, `coupon_amount` DECIMAL(19,4) ) 3 rows from Discount_Coupons table: coupon_id date_issued coupon_amount 1 2017-09-06 01:33:27 500.00 2 2018-02-20 09:40:56 686.25 3 2017-09-17 23:31:36 501.30 CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `coupon_id` INTEGER NOT NULL, `good_or_bad_customer` VARCHAR(4), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `gender_mf` VARCHAR(1), `date_became_customer` DATETIME, `date_last_hire` DATETIME, FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` ) ) 3 rows from Customers table: customer_id coupon_id good_or_bad_customer first_name last_name gender_mf date_became_customer date_last_hire 1 12 good Geovany Homenick 0 2017-10-20 12:13:17 2018-02-27 18:55:26 2 14 good Jailyn Gerlach 0 2015-04-06 21:18:37 2018-01-30 04:47:13 3 7 good Rosalee Kessler 0 2016-02-03 16:58:11 2018-03-04 21:30:23 CREATE TABLE `Bookings` ( `booking_id` INTEGER PRIMARY KEY , `customer_id` INTEGER NOT NULL, `booking_status_code` VARCHAR(10) NOT NULL, `returned_damaged_yn` VARCHAR(40), `booking_start_date` DATETIME, `booking_end_date` DATETIME, `count_hired` VARCHAR(40), `amount_payable` DECIMAL(19,4), `amount_of_discount` DECIMAL(19,4), `amount_outstanding` DECIMAL(19,4), `amount_of_refund` DECIMAL(19,4), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Bookings table: booking_id customer_id booking_status_code returned_damaged_yn booking_start_date booking_end_date count_hired amount_payable amount_of_discount amount_outstanding amount_of_refund 1 7 Provisional 1 2016-12-07 23:39:17 2018-02-01 16:39:13 298 214.39 71.45 28.22 179.14 2 15 Confirmed 1 2017-06-16 11:42:31 2018-02-19 21:53:31 331 386.92 83.82 57.62 183.68 3 3 Confirmed 1 2017-04-04 11:02:43 2018-02-01 09:30:50 729 351.32 49.26 66.01 135.94 CREATE TABLE `Products_for_Hire` ( `product_id` INTEGER PRIMARY KEY, `product_type_code` VARCHAR(15) NOT NULL, `daily_hire_cost` DECIMAL(19,4), `product_name` VARCHAR(80), `product_description` VARCHAR(255) ) 3 rows from Products_for_Hire table: product_id product_type_code daily_hire_cost product_name product_description 1 Cutlery 26.15 Book collection C Anna Karenina 2 Cutlery 15.62 Book collection B War and Peace 3 Cutlery 39.73 Book collection A The Great Gatsby CREATE TABLE `Payments` ( `payment_id` INTEGER PRIMARY KEY, `booking_id` INTEGER, `customer_id` INTEGER NOT NULL, `payment_type_code` VARCHAR(15) NOT NULL, `amount_paid_in_full_yn` VARCHAR(1), `payment_date` DATETIME, `amount_due` DECIMAL(19,4), `amount_paid` DECIMAL(19,4), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Payments table: payment_id booking_id customer_id payment_type_code amount_paid_in_full_yn payment_date amount_due amount_paid 1 6 15 Check 1 2018-03-09 16:28:00 369.52 206.27 2 9 12 Cash 1 2018-03-03 13:39:44 278.60 666.45 3 5 7 Credit Card 0 2018-03-22 15:00:23 840.06 135.70 CREATE TABLE `Products_Booked` ( `booking_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `returned_yn` VARCHAR(1), `returned_late_yn` VARCHAR(1), `booked_count` INTEGER, `booked_amount` FLOAT NULL, PRIMARY KEY (`booking_id`, `product_id`) FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from Products_Booked table: booking_id product_id returned_yn returned_late_yn booked_count booked_amount 4 1 1 1 5 309.73 14 1 1 0 3 102.76 13 3 1 0 4 151.68 CREATE TABLE `View_Product_Availability` ( `product_id` INTEGER NOT NULL, `booking_id` INTEGER NOT NULL, `status_date` DATETIME PRIMARY KEY, `available_yn` VARCHAR(1), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from View_Product_Availability table: product_id booking_id status_date available_yn 1 5 2018-03-18 05:25:55 1 2 5 2018-03-21 15:20:32 0 3 11 2018-03-25 10:20:15 1
products_for_hire
What are all the distinct payment types?
SELECT DISTINCT payment_type_code FROM payments
CREATE TABLE `Discount_Coupons` ( `coupon_id` INTEGER PRIMARY KEY, `date_issued` DATETIME, `coupon_amount` DECIMAL(19,4) ) 3 rows from Discount_Coupons table: coupon_id date_issued coupon_amount 1 2017-09-06 01:33:27 500.00 2 2018-02-20 09:40:56 686.25 3 2017-09-17 23:31:36 501.30 CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `coupon_id` INTEGER NOT NULL, `good_or_bad_customer` VARCHAR(4), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `gender_mf` VARCHAR(1), `date_became_customer` DATETIME, `date_last_hire` DATETIME, FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` ) ) 3 rows from Customers table: customer_id coupon_id good_or_bad_customer first_name last_name gender_mf date_became_customer date_last_hire 1 12 good Geovany Homenick 0 2017-10-20 12:13:17 2018-02-27 18:55:26 2 14 good Jailyn Gerlach 0 2015-04-06 21:18:37 2018-01-30 04:47:13 3 7 good Rosalee Kessler 0 2016-02-03 16:58:11 2018-03-04 21:30:23 CREATE TABLE `Bookings` ( `booking_id` INTEGER PRIMARY KEY , `customer_id` INTEGER NOT NULL, `booking_status_code` VARCHAR(10) NOT NULL, `returned_damaged_yn` VARCHAR(40), `booking_start_date` DATETIME, `booking_end_date` DATETIME, `count_hired` VARCHAR(40), `amount_payable` DECIMAL(19,4), `amount_of_discount` DECIMAL(19,4), `amount_outstanding` DECIMAL(19,4), `amount_of_refund` DECIMAL(19,4), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Bookings table: booking_id customer_id booking_status_code returned_damaged_yn booking_start_date booking_end_date count_hired amount_payable amount_of_discount amount_outstanding amount_of_refund 1 7 Provisional 1 2016-12-07 23:39:17 2018-02-01 16:39:13 298 214.39 71.45 28.22 179.14 2 15 Confirmed 1 2017-06-16 11:42:31 2018-02-19 21:53:31 331 386.92 83.82 57.62 183.68 3 3 Confirmed 1 2017-04-04 11:02:43 2018-02-01 09:30:50 729 351.32 49.26 66.01 135.94 CREATE TABLE `Products_for_Hire` ( `product_id` INTEGER PRIMARY KEY, `product_type_code` VARCHAR(15) NOT NULL, `daily_hire_cost` DECIMAL(19,4), `product_name` VARCHAR(80), `product_description` VARCHAR(255) ) 3 rows from Products_for_Hire table: product_id product_type_code daily_hire_cost product_name product_description 1 Cutlery 26.15 Book collection C Anna Karenina 2 Cutlery 15.62 Book collection B War and Peace 3 Cutlery 39.73 Book collection A The Great Gatsby CREATE TABLE `Payments` ( `payment_id` INTEGER PRIMARY KEY, `booking_id` INTEGER, `customer_id` INTEGER NOT NULL, `payment_type_code` VARCHAR(15) NOT NULL, `amount_paid_in_full_yn` VARCHAR(1), `payment_date` DATETIME, `amount_due` DECIMAL(19,4), `amount_paid` DECIMAL(19,4), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Payments table: payment_id booking_id customer_id payment_type_code amount_paid_in_full_yn payment_date amount_due amount_paid 1 6 15 Check 1 2018-03-09 16:28:00 369.52 206.27 2 9 12 Cash 1 2018-03-03 13:39:44 278.60 666.45 3 5 7 Credit Card 0 2018-03-22 15:00:23 840.06 135.70 CREATE TABLE `Products_Booked` ( `booking_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `returned_yn` VARCHAR(1), `returned_late_yn` VARCHAR(1), `booked_count` INTEGER, `booked_amount` FLOAT NULL, PRIMARY KEY (`booking_id`, `product_id`) FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from Products_Booked table: booking_id product_id returned_yn returned_late_yn booked_count booked_amount 4 1 1 1 5 309.73 14 1 1 0 3 102.76 13 3 1 0 4 151.68 CREATE TABLE `View_Product_Availability` ( `product_id` INTEGER NOT NULL, `booking_id` INTEGER NOT NULL, `status_date` DATETIME PRIMARY KEY, `available_yn` VARCHAR(1), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from View_Product_Availability table: product_id booking_id status_date available_yn 1 5 2018-03-18 05:25:55 1 2 5 2018-03-21 15:20:32 0 3 11 2018-03-25 10:20:15 1
products_for_hire
What are the daily hire costs for the products with substring 'Book' in its name?
SELECT daily_hire_cost FROM Products_for_hire WHERE product_name LIKE '%Book%'
CREATE TABLE `Discount_Coupons` ( `coupon_id` INTEGER PRIMARY KEY, `date_issued` DATETIME, `coupon_amount` DECIMAL(19,4) ) 3 rows from Discount_Coupons table: coupon_id date_issued coupon_amount 1 2017-09-06 01:33:27 500.00 2 2018-02-20 09:40:56 686.25 3 2017-09-17 23:31:36 501.30 CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `coupon_id` INTEGER NOT NULL, `good_or_bad_customer` VARCHAR(4), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `gender_mf` VARCHAR(1), `date_became_customer` DATETIME, `date_last_hire` DATETIME, FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` ) ) 3 rows from Customers table: customer_id coupon_id good_or_bad_customer first_name last_name gender_mf date_became_customer date_last_hire 1 12 good Geovany Homenick 0 2017-10-20 12:13:17 2018-02-27 18:55:26 2 14 good Jailyn Gerlach 0 2015-04-06 21:18:37 2018-01-30 04:47:13 3 7 good Rosalee Kessler 0 2016-02-03 16:58:11 2018-03-04 21:30:23 CREATE TABLE `Bookings` ( `booking_id` INTEGER PRIMARY KEY , `customer_id` INTEGER NOT NULL, `booking_status_code` VARCHAR(10) NOT NULL, `returned_damaged_yn` VARCHAR(40), `booking_start_date` DATETIME, `booking_end_date` DATETIME, `count_hired` VARCHAR(40), `amount_payable` DECIMAL(19,4), `amount_of_discount` DECIMAL(19,4), `amount_outstanding` DECIMAL(19,4), `amount_of_refund` DECIMAL(19,4), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Bookings table: booking_id customer_id booking_status_code returned_damaged_yn booking_start_date booking_end_date count_hired amount_payable amount_of_discount amount_outstanding amount_of_refund 1 7 Provisional 1 2016-12-07 23:39:17 2018-02-01 16:39:13 298 214.39 71.45 28.22 179.14 2 15 Confirmed 1 2017-06-16 11:42:31 2018-02-19 21:53:31 331 386.92 83.82 57.62 183.68 3 3 Confirmed 1 2017-04-04 11:02:43 2018-02-01 09:30:50 729 351.32 49.26 66.01 135.94 CREATE TABLE `Products_for_Hire` ( `product_id` INTEGER PRIMARY KEY, `product_type_code` VARCHAR(15) NOT NULL, `daily_hire_cost` DECIMAL(19,4), `product_name` VARCHAR(80), `product_description` VARCHAR(255) ) 3 rows from Products_for_Hire table: product_id product_type_code daily_hire_cost product_name product_description 1 Cutlery 26.15 Book collection C Anna Karenina 2 Cutlery 15.62 Book collection B War and Peace 3 Cutlery 39.73 Book collection A The Great Gatsby CREATE TABLE `Payments` ( `payment_id` INTEGER PRIMARY KEY, `booking_id` INTEGER, `customer_id` INTEGER NOT NULL, `payment_type_code` VARCHAR(15) NOT NULL, `amount_paid_in_full_yn` VARCHAR(1), `payment_date` DATETIME, `amount_due` DECIMAL(19,4), `amount_paid` DECIMAL(19,4), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Payments table: payment_id booking_id customer_id payment_type_code amount_paid_in_full_yn payment_date amount_due amount_paid 1 6 15 Check 1 2018-03-09 16:28:00 369.52 206.27 2 9 12 Cash 1 2018-03-03 13:39:44 278.60 666.45 3 5 7 Credit Card 0 2018-03-22 15:00:23 840.06 135.70 CREATE TABLE `Products_Booked` ( `booking_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `returned_yn` VARCHAR(1), `returned_late_yn` VARCHAR(1), `booked_count` INTEGER, `booked_amount` FLOAT NULL, PRIMARY KEY (`booking_id`, `product_id`) FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from Products_Booked table: booking_id product_id returned_yn returned_late_yn booked_count booked_amount 4 1 1 1 5 309.73 14 1 1 0 3 102.76 13 3 1 0 4 151.68 CREATE TABLE `View_Product_Availability` ( `product_id` INTEGER NOT NULL, `booking_id` INTEGER NOT NULL, `status_date` DATETIME PRIMARY KEY, `available_yn` VARCHAR(1), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from View_Product_Availability table: product_id booking_id status_date available_yn 1 5 2018-03-18 05:25:55 1 2 5 2018-03-21 15:20:32 0 3 11 2018-03-25 10:20:15 1
products_for_hire
How many products are never booked with amount higher than 200?
SELECT count(*) FROM Products_for_hire WHERE product_id NOT IN ( SELECT product_id FROM products_booked WHERE booked_amount > 200 )
CREATE TABLE `Discount_Coupons` ( `coupon_id` INTEGER PRIMARY KEY, `date_issued` DATETIME, `coupon_amount` DECIMAL(19,4) ) 3 rows from Discount_Coupons table: coupon_id date_issued coupon_amount 1 2017-09-06 01:33:27 500.00 2 2018-02-20 09:40:56 686.25 3 2017-09-17 23:31:36 501.30 CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `coupon_id` INTEGER NOT NULL, `good_or_bad_customer` VARCHAR(4), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `gender_mf` VARCHAR(1), `date_became_customer` DATETIME, `date_last_hire` DATETIME, FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` ) ) 3 rows from Customers table: customer_id coupon_id good_or_bad_customer first_name last_name gender_mf date_became_customer date_last_hire 1 12 good Geovany Homenick 0 2017-10-20 12:13:17 2018-02-27 18:55:26 2 14 good Jailyn Gerlach 0 2015-04-06 21:18:37 2018-01-30 04:47:13 3 7 good Rosalee Kessler 0 2016-02-03 16:58:11 2018-03-04 21:30:23 CREATE TABLE `Bookings` ( `booking_id` INTEGER PRIMARY KEY , `customer_id` INTEGER NOT NULL, `booking_status_code` VARCHAR(10) NOT NULL, `returned_damaged_yn` VARCHAR(40), `booking_start_date` DATETIME, `booking_end_date` DATETIME, `count_hired` VARCHAR(40), `amount_payable` DECIMAL(19,4), `amount_of_discount` DECIMAL(19,4), `amount_outstanding` DECIMAL(19,4), `amount_of_refund` DECIMAL(19,4), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Bookings table: booking_id customer_id booking_status_code returned_damaged_yn booking_start_date booking_end_date count_hired amount_payable amount_of_discount amount_outstanding amount_of_refund 1 7 Provisional 1 2016-12-07 23:39:17 2018-02-01 16:39:13 298 214.39 71.45 28.22 179.14 2 15 Confirmed 1 2017-06-16 11:42:31 2018-02-19 21:53:31 331 386.92 83.82 57.62 183.68 3 3 Confirmed 1 2017-04-04 11:02:43 2018-02-01 09:30:50 729 351.32 49.26 66.01 135.94 CREATE TABLE `Products_for_Hire` ( `product_id` INTEGER PRIMARY KEY, `product_type_code` VARCHAR(15) NOT NULL, `daily_hire_cost` DECIMAL(19,4), `product_name` VARCHAR(80), `product_description` VARCHAR(255) ) 3 rows from Products_for_Hire table: product_id product_type_code daily_hire_cost product_name product_description 1 Cutlery 26.15 Book collection C Anna Karenina 2 Cutlery 15.62 Book collection B War and Peace 3 Cutlery 39.73 Book collection A The Great Gatsby CREATE TABLE `Payments` ( `payment_id` INTEGER PRIMARY KEY, `booking_id` INTEGER, `customer_id` INTEGER NOT NULL, `payment_type_code` VARCHAR(15) NOT NULL, `amount_paid_in_full_yn` VARCHAR(1), `payment_date` DATETIME, `amount_due` DECIMAL(19,4), `amount_paid` DECIMAL(19,4), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Payments table: payment_id booking_id customer_id payment_type_code amount_paid_in_full_yn payment_date amount_due amount_paid 1 6 15 Check 1 2018-03-09 16:28:00 369.52 206.27 2 9 12 Cash 1 2018-03-03 13:39:44 278.60 666.45 3 5 7 Credit Card 0 2018-03-22 15:00:23 840.06 135.70 CREATE TABLE `Products_Booked` ( `booking_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `returned_yn` VARCHAR(1), `returned_late_yn` VARCHAR(1), `booked_count` INTEGER, `booked_amount` FLOAT NULL, PRIMARY KEY (`booking_id`, `product_id`) FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from Products_Booked table: booking_id product_id returned_yn returned_late_yn booked_count booked_amount 4 1 1 1 5 309.73 14 1 1 0 3 102.76 13 3 1 0 4 151.68 CREATE TABLE `View_Product_Availability` ( `product_id` INTEGER NOT NULL, `booking_id` INTEGER NOT NULL, `status_date` DATETIME PRIMARY KEY, `available_yn` VARCHAR(1), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from View_Product_Availability table: product_id booking_id status_date available_yn 1 5 2018-03-18 05:25:55 1 2 5 2018-03-21 15:20:32 0 3 11 2018-03-25 10:20:15 1
products_for_hire
What are the coupon amount of the coupons owned by both good and bad customers?
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'
CREATE TABLE `Discount_Coupons` ( `coupon_id` INTEGER PRIMARY KEY, `date_issued` DATETIME, `coupon_amount` DECIMAL(19,4) ) 3 rows from Discount_Coupons table: coupon_id date_issued coupon_amount 1 2017-09-06 01:33:27 500.00 2 2018-02-20 09:40:56 686.25 3 2017-09-17 23:31:36 501.30 CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `coupon_id` INTEGER NOT NULL, `good_or_bad_customer` VARCHAR(4), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `gender_mf` VARCHAR(1), `date_became_customer` DATETIME, `date_last_hire` DATETIME, FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` ) ) 3 rows from Customers table: customer_id coupon_id good_or_bad_customer first_name last_name gender_mf date_became_customer date_last_hire 1 12 good Geovany Homenick 0 2017-10-20 12:13:17 2018-02-27 18:55:26 2 14 good Jailyn Gerlach 0 2015-04-06 21:18:37 2018-01-30 04:47:13 3 7 good Rosalee Kessler 0 2016-02-03 16:58:11 2018-03-04 21:30:23 CREATE TABLE `Bookings` ( `booking_id` INTEGER PRIMARY KEY , `customer_id` INTEGER NOT NULL, `booking_status_code` VARCHAR(10) NOT NULL, `returned_damaged_yn` VARCHAR(40), `booking_start_date` DATETIME, `booking_end_date` DATETIME, `count_hired` VARCHAR(40), `amount_payable` DECIMAL(19,4), `amount_of_discount` DECIMAL(19,4), `amount_outstanding` DECIMAL(19,4), `amount_of_refund` DECIMAL(19,4), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Bookings table: booking_id customer_id booking_status_code returned_damaged_yn booking_start_date booking_end_date count_hired amount_payable amount_of_discount amount_outstanding amount_of_refund 1 7 Provisional 1 2016-12-07 23:39:17 2018-02-01 16:39:13 298 214.39 71.45 28.22 179.14 2 15 Confirmed 1 2017-06-16 11:42:31 2018-02-19 21:53:31 331 386.92 83.82 57.62 183.68 3 3 Confirmed 1 2017-04-04 11:02:43 2018-02-01 09:30:50 729 351.32 49.26 66.01 135.94 CREATE TABLE `Products_for_Hire` ( `product_id` INTEGER PRIMARY KEY, `product_type_code` VARCHAR(15) NOT NULL, `daily_hire_cost` DECIMAL(19,4), `product_name` VARCHAR(80), `product_description` VARCHAR(255) ) 3 rows from Products_for_Hire table: product_id product_type_code daily_hire_cost product_name product_description 1 Cutlery 26.15 Book collection C Anna Karenina 2 Cutlery 15.62 Book collection B War and Peace 3 Cutlery 39.73 Book collection A The Great Gatsby CREATE TABLE `Payments` ( `payment_id` INTEGER PRIMARY KEY, `booking_id` INTEGER, `customer_id` INTEGER NOT NULL, `payment_type_code` VARCHAR(15) NOT NULL, `amount_paid_in_full_yn` VARCHAR(1), `payment_date` DATETIME, `amount_due` DECIMAL(19,4), `amount_paid` DECIMAL(19,4), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Payments table: payment_id booking_id customer_id payment_type_code amount_paid_in_full_yn payment_date amount_due amount_paid 1 6 15 Check 1 2018-03-09 16:28:00 369.52 206.27 2 9 12 Cash 1 2018-03-03 13:39:44 278.60 666.45 3 5 7 Credit Card 0 2018-03-22 15:00:23 840.06 135.70 CREATE TABLE `Products_Booked` ( `booking_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `returned_yn` VARCHAR(1), `returned_late_yn` VARCHAR(1), `booked_count` INTEGER, `booked_amount` FLOAT NULL, PRIMARY KEY (`booking_id`, `product_id`) FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from Products_Booked table: booking_id product_id returned_yn returned_late_yn booked_count booked_amount 4 1 1 1 5 309.73 14 1 1 0 3 102.76 13 3 1 0 4 151.68 CREATE TABLE `View_Product_Availability` ( `product_id` INTEGER NOT NULL, `booking_id` INTEGER NOT NULL, `status_date` DATETIME PRIMARY KEY, `available_yn` VARCHAR(1), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from View_Product_Availability table: product_id booking_id status_date available_yn 1 5 2018-03-18 05:25:55 1 2 5 2018-03-21 15:20:32 0 3 11 2018-03-25 10:20:15 1
products_for_hire
What are the payment date of the payment with amount paid higher than 300 or with payment type is 'Check'
SELECT payment_date FROM payments WHERE amount_paid > 300 OR payment_type_code = 'Check'
CREATE TABLE `Discount_Coupons` ( `coupon_id` INTEGER PRIMARY KEY, `date_issued` DATETIME, `coupon_amount` DECIMAL(19,4) ) 3 rows from Discount_Coupons table: coupon_id date_issued coupon_amount 1 2017-09-06 01:33:27 500.00 2 2018-02-20 09:40:56 686.25 3 2017-09-17 23:31:36 501.30 CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `coupon_id` INTEGER NOT NULL, `good_or_bad_customer` VARCHAR(4), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `gender_mf` VARCHAR(1), `date_became_customer` DATETIME, `date_last_hire` DATETIME, FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` ) ) 3 rows from Customers table: customer_id coupon_id good_or_bad_customer first_name last_name gender_mf date_became_customer date_last_hire 1 12 good Geovany Homenick 0 2017-10-20 12:13:17 2018-02-27 18:55:26 2 14 good Jailyn Gerlach 0 2015-04-06 21:18:37 2018-01-30 04:47:13 3 7 good Rosalee Kessler 0 2016-02-03 16:58:11 2018-03-04 21:30:23 CREATE TABLE `Bookings` ( `booking_id` INTEGER PRIMARY KEY , `customer_id` INTEGER NOT NULL, `booking_status_code` VARCHAR(10) NOT NULL, `returned_damaged_yn` VARCHAR(40), `booking_start_date` DATETIME, `booking_end_date` DATETIME, `count_hired` VARCHAR(40), `amount_payable` DECIMAL(19,4), `amount_of_discount` DECIMAL(19,4), `amount_outstanding` DECIMAL(19,4), `amount_of_refund` DECIMAL(19,4), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Bookings table: booking_id customer_id booking_status_code returned_damaged_yn booking_start_date booking_end_date count_hired amount_payable amount_of_discount amount_outstanding amount_of_refund 1 7 Provisional 1 2016-12-07 23:39:17 2018-02-01 16:39:13 298 214.39 71.45 28.22 179.14 2 15 Confirmed 1 2017-06-16 11:42:31 2018-02-19 21:53:31 331 386.92 83.82 57.62 183.68 3 3 Confirmed 1 2017-04-04 11:02:43 2018-02-01 09:30:50 729 351.32 49.26 66.01 135.94 CREATE TABLE `Products_for_Hire` ( `product_id` INTEGER PRIMARY KEY, `product_type_code` VARCHAR(15) NOT NULL, `daily_hire_cost` DECIMAL(19,4), `product_name` VARCHAR(80), `product_description` VARCHAR(255) ) 3 rows from Products_for_Hire table: product_id product_type_code daily_hire_cost product_name product_description 1 Cutlery 26.15 Book collection C Anna Karenina 2 Cutlery 15.62 Book collection B War and Peace 3 Cutlery 39.73 Book collection A The Great Gatsby CREATE TABLE `Payments` ( `payment_id` INTEGER PRIMARY KEY, `booking_id` INTEGER, `customer_id` INTEGER NOT NULL, `payment_type_code` VARCHAR(15) NOT NULL, `amount_paid_in_full_yn` VARCHAR(1), `payment_date` DATETIME, `amount_due` DECIMAL(19,4), `amount_paid` DECIMAL(19,4), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Payments table: payment_id booking_id customer_id payment_type_code amount_paid_in_full_yn payment_date amount_due amount_paid 1 6 15 Check 1 2018-03-09 16:28:00 369.52 206.27 2 9 12 Cash 1 2018-03-03 13:39:44 278.60 666.45 3 5 7 Credit Card 0 2018-03-22 15:00:23 840.06 135.70 CREATE TABLE `Products_Booked` ( `booking_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `returned_yn` VARCHAR(1), `returned_late_yn` VARCHAR(1), `booked_count` INTEGER, `booked_amount` FLOAT NULL, PRIMARY KEY (`booking_id`, `product_id`) FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from Products_Booked table: booking_id product_id returned_yn returned_late_yn booked_count booked_amount 4 1 1 1 5 309.73 14 1 1 0 3 102.76 13 3 1 0 4 151.68 CREATE TABLE `View_Product_Availability` ( `product_id` INTEGER NOT NULL, `booking_id` INTEGER NOT NULL, `status_date` DATETIME PRIMARY KEY, `available_yn` VARCHAR(1), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from View_Product_Availability table: product_id booking_id status_date available_yn 1 5 2018-03-18 05:25:55 1 2 5 2018-03-21 15:20:32 0 3 11 2018-03-25 10:20:15 1
products_for_hire
What are the names and descriptions of the products that are of 'Cutlery' type and have daily hire cost lower than 20?
SELECT product_name , product_description FROM products_for_hire WHERE product_type_code = 'Cutlery' AND daily_hire_cost < 20
CREATE TABLE `Discount_Coupons` ( `coupon_id` INTEGER PRIMARY KEY, `date_issued` DATETIME, `coupon_amount` DECIMAL(19,4) ) 3 rows from Discount_Coupons table: coupon_id date_issued coupon_amount 1 2017-09-06 01:33:27 500.00 2 2018-02-20 09:40:56 686.25 3 2017-09-17 23:31:36 501.30 CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `coupon_id` INTEGER NOT NULL, `good_or_bad_customer` VARCHAR(4), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `gender_mf` VARCHAR(1), `date_became_customer` DATETIME, `date_last_hire` DATETIME, FOREIGN KEY (`coupon_id` ) REFERENCES `Discount_Coupons`(`coupon_id` ) ) 3 rows from Customers table: customer_id coupon_id good_or_bad_customer first_name last_name gender_mf date_became_customer date_last_hire 1 12 good Geovany Homenick 0 2017-10-20 12:13:17 2018-02-27 18:55:26 2 14 good Jailyn Gerlach 0 2015-04-06 21:18:37 2018-01-30 04:47:13 3 7 good Rosalee Kessler 0 2016-02-03 16:58:11 2018-03-04 21:30:23 CREATE TABLE `Bookings` ( `booking_id` INTEGER PRIMARY KEY , `customer_id` INTEGER NOT NULL, `booking_status_code` VARCHAR(10) NOT NULL, `returned_damaged_yn` VARCHAR(40), `booking_start_date` DATETIME, `booking_end_date` DATETIME, `count_hired` VARCHAR(40), `amount_payable` DECIMAL(19,4), `amount_of_discount` DECIMAL(19,4), `amount_outstanding` DECIMAL(19,4), `amount_of_refund` DECIMAL(19,4), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Bookings table: booking_id customer_id booking_status_code returned_damaged_yn booking_start_date booking_end_date count_hired amount_payable amount_of_discount amount_outstanding amount_of_refund 1 7 Provisional 1 2016-12-07 23:39:17 2018-02-01 16:39:13 298 214.39 71.45 28.22 179.14 2 15 Confirmed 1 2017-06-16 11:42:31 2018-02-19 21:53:31 331 386.92 83.82 57.62 183.68 3 3 Confirmed 1 2017-04-04 11:02:43 2018-02-01 09:30:50 729 351.32 49.26 66.01 135.94 CREATE TABLE `Products_for_Hire` ( `product_id` INTEGER PRIMARY KEY, `product_type_code` VARCHAR(15) NOT NULL, `daily_hire_cost` DECIMAL(19,4), `product_name` VARCHAR(80), `product_description` VARCHAR(255) ) 3 rows from Products_for_Hire table: product_id product_type_code daily_hire_cost product_name product_description 1 Cutlery 26.15 Book collection C Anna Karenina 2 Cutlery 15.62 Book collection B War and Peace 3 Cutlery 39.73 Book collection A The Great Gatsby CREATE TABLE `Payments` ( `payment_id` INTEGER PRIMARY KEY, `booking_id` INTEGER, `customer_id` INTEGER NOT NULL, `payment_type_code` VARCHAR(15) NOT NULL, `amount_paid_in_full_yn` VARCHAR(1), `payment_date` DATETIME, `amount_due` DECIMAL(19,4), `amount_paid` DECIMAL(19,4), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Payments table: payment_id booking_id customer_id payment_type_code amount_paid_in_full_yn payment_date amount_due amount_paid 1 6 15 Check 1 2018-03-09 16:28:00 369.52 206.27 2 9 12 Cash 1 2018-03-03 13:39:44 278.60 666.45 3 5 7 Credit Card 0 2018-03-22 15:00:23 840.06 135.70 CREATE TABLE `Products_Booked` ( `booking_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `returned_yn` VARCHAR(1), `returned_late_yn` VARCHAR(1), `booked_count` INTEGER, `booked_amount` FLOAT NULL, PRIMARY KEY (`booking_id`, `product_id`) FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from Products_Booked table: booking_id product_id returned_yn returned_late_yn booked_count booked_amount 4 1 1 1 5 309.73 14 1 1 0 3 102.76 13 3 1 0 4 151.68 CREATE TABLE `View_Product_Availability` ( `product_id` INTEGER NOT NULL, `booking_id` INTEGER NOT NULL, `status_date` DATETIME PRIMARY KEY, `available_yn` VARCHAR(1), FOREIGN KEY (`booking_id` ) REFERENCES `Bookings`(`booking_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products_for_Hire`(`product_id` ) ) 3 rows from View_Product_Availability table: product_id booking_id status_date available_yn 1 5 2018-03-18 05:25:55 1 2 5 2018-03-21 15:20:32 0 3 11 2018-03-25 10:20:15 1
phone_market
How many phones are there?
SELECT count(*) FROM phone
CREATE TABLE "phone" ( "Name" text, "Phone_ID" int, "Memory_in_G" int, "Carrier" text, "Price" real, PRIMARY KEY ("Phone_ID") ) 3 rows from phone table: Name Phone_ID Memory_in_G Carrier Price IPhone 5s 1 32 Sprint 320.0 IPhone 6 5 128 Sprint 480.0 IPhone 6s 2 128 TMobile 699.0 CREATE TABLE "market" ( "Market_ID" int, "District" text, "Num_of_employees" int, "Num_of_shops" real, "Ranking" int, PRIMARY KEY ("Market_ID") ) 3 rows from market table: Market_ID District Num_of_employees Num_of_shops Ranking 1 Alberta 1966 40.0 1 2 British Columbia 1965 49.0 21 3 New Brunswick 1978 10.0 4 CREATE TABLE "phone_market" ( "Market_ID" int, "Phone_ID" text, "Num_of_stock" int, PRIMARY KEY ("Market_ID","Phone_ID"), FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"), FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID") ) 3 rows from phone_market table: Market_ID Phone_ID Num_of_stock 1 1 2232 2 2 4324 1 4 874
phone_market
List the names of phones in ascending order of price.
SELECT Name FROM phone ORDER BY Price ASC
CREATE TABLE "phone" ( "Name" text, "Phone_ID" int, "Memory_in_G" int, "Carrier" text, "Price" real, PRIMARY KEY ("Phone_ID") ) 3 rows from phone table: Name Phone_ID Memory_in_G Carrier Price IPhone 5s 1 32 Sprint 320.0 IPhone 6 5 128 Sprint 480.0 IPhone 6s 2 128 TMobile 699.0 CREATE TABLE "market" ( "Market_ID" int, "District" text, "Num_of_employees" int, "Num_of_shops" real, "Ranking" int, PRIMARY KEY ("Market_ID") ) 3 rows from market table: Market_ID District Num_of_employees Num_of_shops Ranking 1 Alberta 1966 40.0 1 2 British Columbia 1965 49.0 21 3 New Brunswick 1978 10.0 4 CREATE TABLE "phone_market" ( "Market_ID" int, "Phone_ID" text, "Num_of_stock" int, PRIMARY KEY ("Market_ID","Phone_ID"), FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"), FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID") ) 3 rows from phone_market table: Market_ID Phone_ID Num_of_stock 1 1 2232 2 2 4324 1 4 874
phone_market
What are the memories and carriers of phones?
SELECT Memory_in_G , Carrier FROM phone
CREATE TABLE "phone" ( "Name" text, "Phone_ID" int, "Memory_in_G" int, "Carrier" text, "Price" real, PRIMARY KEY ("Phone_ID") ) 3 rows from phone table: Name Phone_ID Memory_in_G Carrier Price IPhone 5s 1 32 Sprint 320.0 IPhone 6 5 128 Sprint 480.0 IPhone 6s 2 128 TMobile 699.0 CREATE TABLE "market" ( "Market_ID" int, "District" text, "Num_of_employees" int, "Num_of_shops" real, "Ranking" int, PRIMARY KEY ("Market_ID") ) 3 rows from market table: Market_ID District Num_of_employees Num_of_shops Ranking 1 Alberta 1966 40.0 1 2 British Columbia 1965 49.0 21 3 New Brunswick 1978 10.0 4 CREATE TABLE "phone_market" ( "Market_ID" int, "Phone_ID" text, "Num_of_stock" int, PRIMARY KEY ("Market_ID","Phone_ID"), FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"), FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID") ) 3 rows from phone_market table: Market_ID Phone_ID Num_of_stock 1 1 2232 2 2 4324 1 4 874
phone_market
List the distinct carriers of phones with memories bigger than 32.
SELECT DISTINCT Carrier FROM phone WHERE Memory_in_G > 32
CREATE TABLE "phone" ( "Name" text, "Phone_ID" int, "Memory_in_G" int, "Carrier" text, "Price" real, PRIMARY KEY ("Phone_ID") ) 3 rows from phone table: Name Phone_ID Memory_in_G Carrier Price IPhone 5s 1 32 Sprint 320.0 IPhone 6 5 128 Sprint 480.0 IPhone 6s 2 128 TMobile 699.0 CREATE TABLE "market" ( "Market_ID" int, "District" text, "Num_of_employees" int, "Num_of_shops" real, "Ranking" int, PRIMARY KEY ("Market_ID") ) 3 rows from market table: Market_ID District Num_of_employees Num_of_shops Ranking 1 Alberta 1966 40.0 1 2 British Columbia 1965 49.0 21 3 New Brunswick 1978 10.0 4 CREATE TABLE "phone_market" ( "Market_ID" int, "Phone_ID" text, "Num_of_stock" int, PRIMARY KEY ("Market_ID","Phone_ID"), FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"), FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID") ) 3 rows from phone_market table: Market_ID Phone_ID Num_of_stock 1 1 2232 2 2 4324 1 4 874
phone_market
Show the names of phones with carrier either "Sprint" or "TMobile".
SELECT Name FROM phone WHERE Carrier = "Sprint" OR Carrier = "TMobile"
CREATE TABLE "phone" ( "Name" text, "Phone_ID" int, "Memory_in_G" int, "Carrier" text, "Price" real, PRIMARY KEY ("Phone_ID") ) 3 rows from phone table: Name Phone_ID Memory_in_G Carrier Price IPhone 5s 1 32 Sprint 320.0 IPhone 6 5 128 Sprint 480.0 IPhone 6s 2 128 TMobile 699.0 CREATE TABLE "market" ( "Market_ID" int, "District" text, "Num_of_employees" int, "Num_of_shops" real, "Ranking" int, PRIMARY KEY ("Market_ID") ) 3 rows from market table: Market_ID District Num_of_employees Num_of_shops Ranking 1 Alberta 1966 40.0 1 2 British Columbia 1965 49.0 21 3 New Brunswick 1978 10.0 4 CREATE TABLE "phone_market" ( "Market_ID" int, "Phone_ID" text, "Num_of_stock" int, PRIMARY KEY ("Market_ID","Phone_ID"), FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"), FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID") ) 3 rows from phone_market table: Market_ID Phone_ID Num_of_stock 1 1 2232 2 2 4324 1 4 874
phone_market
What is the carrier of the most expensive phone?
SELECT Carrier FROM phone ORDER BY Price DESC LIMIT 1
CREATE TABLE "phone" ( "Name" text, "Phone_ID" int, "Memory_in_G" int, "Carrier" text, "Price" real, PRIMARY KEY ("Phone_ID") ) 3 rows from phone table: Name Phone_ID Memory_in_G Carrier Price IPhone 5s 1 32 Sprint 320.0 IPhone 6 5 128 Sprint 480.0 IPhone 6s 2 128 TMobile 699.0 CREATE TABLE "market" ( "Market_ID" int, "District" text, "Num_of_employees" int, "Num_of_shops" real, "Ranking" int, PRIMARY KEY ("Market_ID") ) 3 rows from market table: Market_ID District Num_of_employees Num_of_shops Ranking 1 Alberta 1966 40.0 1 2 British Columbia 1965 49.0 21 3 New Brunswick 1978 10.0 4 CREATE TABLE "phone_market" ( "Market_ID" int, "Phone_ID" text, "Num_of_stock" int, PRIMARY KEY ("Market_ID","Phone_ID"), FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"), FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID") ) 3 rows from phone_market table: Market_ID Phone_ID Num_of_stock 1 1 2232 2 2 4324 1 4 874
phone_market
Show different carriers of phones together with the number of phones with each carrier.
SELECT Carrier , COUNT(*) FROM phone GROUP BY Carrier
CREATE TABLE "phone" ( "Name" text, "Phone_ID" int, "Memory_in_G" int, "Carrier" text, "Price" real, PRIMARY KEY ("Phone_ID") ) 3 rows from phone table: Name Phone_ID Memory_in_G Carrier Price IPhone 5s 1 32 Sprint 320.0 IPhone 6 5 128 Sprint 480.0 IPhone 6s 2 128 TMobile 699.0 CREATE TABLE "market" ( "Market_ID" int, "District" text, "Num_of_employees" int, "Num_of_shops" real, "Ranking" int, PRIMARY KEY ("Market_ID") ) 3 rows from market table: Market_ID District Num_of_employees Num_of_shops Ranking 1 Alberta 1966 40.0 1 2 British Columbia 1965 49.0 21 3 New Brunswick 1978 10.0 4 CREATE TABLE "phone_market" ( "Market_ID" int, "Phone_ID" text, "Num_of_stock" int, PRIMARY KEY ("Market_ID","Phone_ID"), FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"), FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID") ) 3 rows from phone_market table: Market_ID Phone_ID Num_of_stock 1 1 2232 2 2 4324 1 4 874
phone_market
Show the most frequently used carrier of the phones.
SELECT Carrier FROM phone GROUP BY Carrier ORDER BY COUNT(*) DESC LIMIT 1
CREATE TABLE "phone" ( "Name" text, "Phone_ID" int, "Memory_in_G" int, "Carrier" text, "Price" real, PRIMARY KEY ("Phone_ID") ) 3 rows from phone table: Name Phone_ID Memory_in_G Carrier Price IPhone 5s 1 32 Sprint 320.0 IPhone 6 5 128 Sprint 480.0 IPhone 6s 2 128 TMobile 699.0 CREATE TABLE "market" ( "Market_ID" int, "District" text, "Num_of_employees" int, "Num_of_shops" real, "Ranking" int, PRIMARY KEY ("Market_ID") ) 3 rows from market table: Market_ID District Num_of_employees Num_of_shops Ranking 1 Alberta 1966 40.0 1 2 British Columbia 1965 49.0 21 3 New Brunswick 1978 10.0 4 CREATE TABLE "phone_market" ( "Market_ID" int, "Phone_ID" text, "Num_of_stock" int, PRIMARY KEY ("Market_ID","Phone_ID"), FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"), FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID") ) 3 rows from phone_market table: Market_ID Phone_ID Num_of_stock 1 1 2232 2 2 4324 1 4 874
phone_market
Show the carriers that have both phones with memory smaller than 32 and phones with memory bigger than 64.
SELECT Carrier FROM phone WHERE Memory_in_G < 32 INTERSECT SELECT Carrier FROM phone WHERE Memory_in_G > 64
CREATE TABLE "phone" ( "Name" text, "Phone_ID" int, "Memory_in_G" int, "Carrier" text, "Price" real, PRIMARY KEY ("Phone_ID") ) 3 rows from phone table: Name Phone_ID Memory_in_G Carrier Price IPhone 5s 1 32 Sprint 320.0 IPhone 6 5 128 Sprint 480.0 IPhone 6s 2 128 TMobile 699.0 CREATE TABLE "market" ( "Market_ID" int, "District" text, "Num_of_employees" int, "Num_of_shops" real, "Ranking" int, PRIMARY KEY ("Market_ID") ) 3 rows from market table: Market_ID District Num_of_employees Num_of_shops Ranking 1 Alberta 1966 40.0 1 2 British Columbia 1965 49.0 21 3 New Brunswick 1978 10.0 4 CREATE TABLE "phone_market" ( "Market_ID" int, "Phone_ID" text, "Num_of_stock" int, PRIMARY KEY ("Market_ID","Phone_ID"), FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"), FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID") ) 3 rows from phone_market table: Market_ID Phone_ID Num_of_stock 1 1 2232 2 2 4324 1 4 874
phone_market
Show the names of phones and the districts of markets they are on.
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
CREATE TABLE "phone" ( "Name" text, "Phone_ID" int, "Memory_in_G" int, "Carrier" text, "Price" real, PRIMARY KEY ("Phone_ID") ) 3 rows from phone table: Name Phone_ID Memory_in_G Carrier Price IPhone 5s 1 32 Sprint 320.0 IPhone 6 5 128 Sprint 480.0 IPhone 6s 2 128 TMobile 699.0 CREATE TABLE "market" ( "Market_ID" int, "District" text, "Num_of_employees" int, "Num_of_shops" real, "Ranking" int, PRIMARY KEY ("Market_ID") ) 3 rows from market table: Market_ID District Num_of_employees Num_of_shops Ranking 1 Alberta 1966 40.0 1 2 British Columbia 1965 49.0 21 3 New Brunswick 1978 10.0 4 CREATE TABLE "phone_market" ( "Market_ID" int, "Phone_ID" text, "Num_of_stock" int, PRIMARY KEY ("Market_ID","Phone_ID"), FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"), FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID") ) 3 rows from phone_market table: Market_ID Phone_ID Num_of_stock 1 1 2232 2 2 4324 1 4 874
phone_market
Show the names of phones and the districts of markets they are on, in ascending order of the ranking of the market.
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
CREATE TABLE "phone" ( "Name" text, "Phone_ID" int, "Memory_in_G" int, "Carrier" text, "Price" real, PRIMARY KEY ("Phone_ID") ) 3 rows from phone table: Name Phone_ID Memory_in_G Carrier Price IPhone 5s 1 32 Sprint 320.0 IPhone 6 5 128 Sprint 480.0 IPhone 6s 2 128 TMobile 699.0 CREATE TABLE "market" ( "Market_ID" int, "District" text, "Num_of_employees" int, "Num_of_shops" real, "Ranking" int, PRIMARY KEY ("Market_ID") ) 3 rows from market table: Market_ID District Num_of_employees Num_of_shops Ranking 1 Alberta 1966 40.0 1 2 British Columbia 1965 49.0 21 3 New Brunswick 1978 10.0 4 CREATE TABLE "phone_market" ( "Market_ID" int, "Phone_ID" text, "Num_of_stock" int, PRIMARY KEY ("Market_ID","Phone_ID"), FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"), FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID") ) 3 rows from phone_market table: Market_ID Phone_ID Num_of_stock 1 1 2232 2 2 4324 1 4 874
phone_market
Show the names of phones that are on market with number of shops greater than 50.
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
CREATE TABLE "phone" ( "Name" text, "Phone_ID" int, "Memory_in_G" int, "Carrier" text, "Price" real, PRIMARY KEY ("Phone_ID") ) 3 rows from phone table: Name Phone_ID Memory_in_G Carrier Price IPhone 5s 1 32 Sprint 320.0 IPhone 6 5 128 Sprint 480.0 IPhone 6s 2 128 TMobile 699.0 CREATE TABLE "market" ( "Market_ID" int, "District" text, "Num_of_employees" int, "Num_of_shops" real, "Ranking" int, PRIMARY KEY ("Market_ID") ) 3 rows from market table: Market_ID District Num_of_employees Num_of_shops Ranking 1 Alberta 1966 40.0 1 2 British Columbia 1965 49.0 21 3 New Brunswick 1978 10.0 4 CREATE TABLE "phone_market" ( "Market_ID" int, "Phone_ID" text, "Num_of_stock" int, PRIMARY KEY ("Market_ID","Phone_ID"), FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"), FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID") ) 3 rows from phone_market table: Market_ID Phone_ID Num_of_stock 1 1 2232 2 2 4324 1 4 874
phone_market
For each phone, show its names and total number of stocks.
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
CREATE TABLE "phone" ( "Name" text, "Phone_ID" int, "Memory_in_G" int, "Carrier" text, "Price" real, PRIMARY KEY ("Phone_ID") ) 3 rows from phone table: Name Phone_ID Memory_in_G Carrier Price IPhone 5s 1 32 Sprint 320.0 IPhone 6 5 128 Sprint 480.0 IPhone 6s 2 128 TMobile 699.0 CREATE TABLE "market" ( "Market_ID" int, "District" text, "Num_of_employees" int, "Num_of_shops" real, "Ranking" int, PRIMARY KEY ("Market_ID") ) 3 rows from market table: Market_ID District Num_of_employees Num_of_shops Ranking 1 Alberta 1966 40.0 1 2 British Columbia 1965 49.0 21 3 New Brunswick 1978 10.0 4 CREATE TABLE "phone_market" ( "Market_ID" int, "Phone_ID" text, "Num_of_stock" int, PRIMARY KEY ("Market_ID","Phone_ID"), FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"), FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID") ) 3 rows from phone_market table: Market_ID Phone_ID Num_of_stock 1 1 2232 2 2 4324 1 4 874
phone_market
Show the names of phones that have total number of stocks bigger than 2000, in descending order of the total number of stocks.
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
CREATE TABLE "phone" ( "Name" text, "Phone_ID" int, "Memory_in_G" int, "Carrier" text, "Price" real, PRIMARY KEY ("Phone_ID") ) 3 rows from phone table: Name Phone_ID Memory_in_G Carrier Price IPhone 5s 1 32 Sprint 320.0 IPhone 6 5 128 Sprint 480.0 IPhone 6s 2 128 TMobile 699.0 CREATE TABLE "market" ( "Market_ID" int, "District" text, "Num_of_employees" int, "Num_of_shops" real, "Ranking" int, PRIMARY KEY ("Market_ID") ) 3 rows from market table: Market_ID District Num_of_employees Num_of_shops Ranking 1 Alberta 1966 40.0 1 2 British Columbia 1965 49.0 21 3 New Brunswick 1978 10.0 4 CREATE TABLE "phone_market" ( "Market_ID" int, "Phone_ID" text, "Num_of_stock" int, PRIMARY KEY ("Market_ID","Phone_ID"), FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"), FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID") ) 3 rows from phone_market table: Market_ID Phone_ID Num_of_stock 1 1 2232 2 2 4324 1 4 874
phone_market
List the names of phones that are not on any market.
SELECT Name FROM phone WHERE Phone_id NOT IN (SELECT Phone_ID FROM phone_market)
CREATE TABLE "phone" ( "Name" text, "Phone_ID" int, "Memory_in_G" int, "Carrier" text, "Price" real, PRIMARY KEY ("Phone_ID") ) 3 rows from phone table: Name Phone_ID Memory_in_G Carrier Price IPhone 5s 1 32 Sprint 320.0 IPhone 6 5 128 Sprint 480.0 IPhone 6s 2 128 TMobile 699.0 CREATE TABLE "market" ( "Market_ID" int, "District" text, "Num_of_employees" int, "Num_of_shops" real, "Ranking" int, PRIMARY KEY ("Market_ID") ) 3 rows from market table: Market_ID District Num_of_employees Num_of_shops Ranking 1 Alberta 1966 40.0 1 2 British Columbia 1965 49.0 21 3 New Brunswick 1978 10.0 4 CREATE TABLE "phone_market" ( "Market_ID" int, "Phone_ID" text, "Num_of_stock" int, PRIMARY KEY ("Market_ID","Phone_ID"), FOREIGN KEY ("Market_ID") REFERENCES `market`("Market_ID"), FOREIGN KEY ("Phone_ID") REFERENCES `phone`("Phone_ID") ) 3 rows from phone_market table: Market_ID Phone_ID Num_of_stock 1 1 2232 2 2 4324 1 4 874
gas_company
How many gas companies are there?
SELECT count(*) FROM company
CREATE TABLE "company" ( "Company_ID" int, "Rank" int, "Company" text, "Headquarters" text, "Main_Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value" real, PRIMARY KEY ("Company_ID") ) 3 rows from company table: Company_ID Rank Company Headquarters Main_Industry Sales_billion Profits_billion Assets_billion Market_Value 1 1 ExxonMobil USA Oil and gas 433.5 41.1 331.1 407.4 2 3 General Electric USA Conglomerate 147.3 14.2 717.2 213.7 3 4 Royal Dutch Shell Netherlands Oil and gas 470.2 30.9 340.5 227.6 CREATE TABLE "gas_station" ( "Station_ID" int, "Open_Year" int, "Location" text, "Manager_Name" text, "Vice_Manager_Name" text, "Representative_Name" text, PRIMARY KEY ("Station_ID") ) 3 rows from gas_station table: Station_ID Open_Year Location Manager_Name Vice_Manager_Name Representative_Name 1 1998 Herne Hill BrianWingrave Russell Denman Clive Burr 2 1999 Channel Hill SimonMarloe Russell Brown Rob Jefferies 3 2000 Reading North Simon Cope Derek Marloe James Colin Dave Edwards Roger CREATE TABLE "station_company" ( "Station_ID" int, "Company_ID" int, "Rank_of_the_Year" int, PRIMARY KEY ("Station_ID","Company_ID"), FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`), FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`) ) 3 rows from station_company table: Station_ID Company_ID Rank_of_the_Year 11 1 1 1 3 2 6 6 3
gas_company
What is the total number of companies?
SELECT count(*) FROM company
CREATE TABLE "company" ( "Company_ID" int, "Rank" int, "Company" text, "Headquarters" text, "Main_Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value" real, PRIMARY KEY ("Company_ID") ) 3 rows from company table: Company_ID Rank Company Headquarters Main_Industry Sales_billion Profits_billion Assets_billion Market_Value 1 1 ExxonMobil USA Oil and gas 433.5 41.1 331.1 407.4 2 3 General Electric USA Conglomerate 147.3 14.2 717.2 213.7 3 4 Royal Dutch Shell Netherlands Oil and gas 470.2 30.9 340.5 227.6 CREATE TABLE "gas_station" ( "Station_ID" int, "Open_Year" int, "Location" text, "Manager_Name" text, "Vice_Manager_Name" text, "Representative_Name" text, PRIMARY KEY ("Station_ID") ) 3 rows from gas_station table: Station_ID Open_Year Location Manager_Name Vice_Manager_Name Representative_Name 1 1998 Herne Hill BrianWingrave Russell Denman Clive Burr 2 1999 Channel Hill SimonMarloe Russell Brown Rob Jefferies 3 2000 Reading North Simon Cope Derek Marloe James Colin Dave Edwards Roger CREATE TABLE "station_company" ( "Station_ID" int, "Company_ID" int, "Rank_of_the_Year" int, PRIMARY KEY ("Station_ID","Company_ID"), FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`), FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`) ) 3 rows from station_company table: Station_ID Company_ID Rank_of_the_Year 11 1 1 1 3 2 6 6 3
gas_company
List the company name and rank for all companies in the decreasing order of their sales.
SELECT company , rank FROM company ORDER BY Sales_billion DESC
CREATE TABLE "company" ( "Company_ID" int, "Rank" int, "Company" text, "Headquarters" text, "Main_Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value" real, PRIMARY KEY ("Company_ID") ) 3 rows from company table: Company_ID Rank Company Headquarters Main_Industry Sales_billion Profits_billion Assets_billion Market_Value 1 1 ExxonMobil USA Oil and gas 433.5 41.1 331.1 407.4 2 3 General Electric USA Conglomerate 147.3 14.2 717.2 213.7 3 4 Royal Dutch Shell Netherlands Oil and gas 470.2 30.9 340.5 227.6 CREATE TABLE "gas_station" ( "Station_ID" int, "Open_Year" int, "Location" text, "Manager_Name" text, "Vice_Manager_Name" text, "Representative_Name" text, PRIMARY KEY ("Station_ID") ) 3 rows from gas_station table: Station_ID Open_Year Location Manager_Name Vice_Manager_Name Representative_Name 1 1998 Herne Hill BrianWingrave Russell Denman Clive Burr 2 1999 Channel Hill SimonMarloe Russell Brown Rob Jefferies 3 2000 Reading North Simon Cope Derek Marloe James Colin Dave Edwards Roger CREATE TABLE "station_company" ( "Station_ID" int, "Company_ID" int, "Rank_of_the_Year" int, PRIMARY KEY ("Station_ID","Company_ID"), FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`), FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`) ) 3 rows from station_company table: Station_ID Company_ID Rank_of_the_Year 11 1 1 1 3 2 6 6 3
gas_company
What is the name and rank of every company ordered by descending number of sales?
SELECT company , rank FROM company ORDER BY Sales_billion DESC
CREATE TABLE "company" ( "Company_ID" int, "Rank" int, "Company" text, "Headquarters" text, "Main_Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value" real, PRIMARY KEY ("Company_ID") ) 3 rows from company table: Company_ID Rank Company Headquarters Main_Industry Sales_billion Profits_billion Assets_billion Market_Value 1 1 ExxonMobil USA Oil and gas 433.5 41.1 331.1 407.4 2 3 General Electric USA Conglomerate 147.3 14.2 717.2 213.7 3 4 Royal Dutch Shell Netherlands Oil and gas 470.2 30.9 340.5 227.6 CREATE TABLE "gas_station" ( "Station_ID" int, "Open_Year" int, "Location" text, "Manager_Name" text, "Vice_Manager_Name" text, "Representative_Name" text, PRIMARY KEY ("Station_ID") ) 3 rows from gas_station table: Station_ID Open_Year Location Manager_Name Vice_Manager_Name Representative_Name 1 1998 Herne Hill BrianWingrave Russell Denman Clive Burr 2 1999 Channel Hill SimonMarloe Russell Brown Rob Jefferies 3 2000 Reading North Simon Cope Derek Marloe James Colin Dave Edwards Roger CREATE TABLE "station_company" ( "Station_ID" int, "Company_ID" int, "Rank_of_the_Year" int, PRIMARY KEY ("Station_ID","Company_ID"), FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`), FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`) ) 3 rows from station_company table: Station_ID Company_ID Rank_of_the_Year 11 1 1 1 3 2 6 6 3
gas_company
Show the company name and the main industry for all companies whose headquarters are not from USA.
SELECT company , main_industry FROM company WHERE headquarters != 'USA'
CREATE TABLE "company" ( "Company_ID" int, "Rank" int, "Company" text, "Headquarters" text, "Main_Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value" real, PRIMARY KEY ("Company_ID") ) 3 rows from company table: Company_ID Rank Company Headquarters Main_Industry Sales_billion Profits_billion Assets_billion Market_Value 1 1 ExxonMobil USA Oil and gas 433.5 41.1 331.1 407.4 2 3 General Electric USA Conglomerate 147.3 14.2 717.2 213.7 3 4 Royal Dutch Shell Netherlands Oil and gas 470.2 30.9 340.5 227.6 CREATE TABLE "gas_station" ( "Station_ID" int, "Open_Year" int, "Location" text, "Manager_Name" text, "Vice_Manager_Name" text, "Representative_Name" text, PRIMARY KEY ("Station_ID") ) 3 rows from gas_station table: Station_ID Open_Year Location Manager_Name Vice_Manager_Name Representative_Name 1 1998 Herne Hill BrianWingrave Russell Denman Clive Burr 2 1999 Channel Hill SimonMarloe Russell Brown Rob Jefferies 3 2000 Reading North Simon Cope Derek Marloe James Colin Dave Edwards Roger CREATE TABLE "station_company" ( "Station_ID" int, "Company_ID" int, "Rank_of_the_Year" int, PRIMARY KEY ("Station_ID","Company_ID"), FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`), FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`) ) 3 rows from station_company table: Station_ID Company_ID Rank_of_the_Year 11 1 1 1 3 2 6 6 3
gas_company
What are the companies and main industries of all companies that are not headquartered in the United States?
SELECT company , main_industry FROM company WHERE headquarters != 'USA'
CREATE TABLE "company" ( "Company_ID" int, "Rank" int, "Company" text, "Headquarters" text, "Main_Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value" real, PRIMARY KEY ("Company_ID") ) 3 rows from company table: Company_ID Rank Company Headquarters Main_Industry Sales_billion Profits_billion Assets_billion Market_Value 1 1 ExxonMobil USA Oil and gas 433.5 41.1 331.1 407.4 2 3 General Electric USA Conglomerate 147.3 14.2 717.2 213.7 3 4 Royal Dutch Shell Netherlands Oil and gas 470.2 30.9 340.5 227.6 CREATE TABLE "gas_station" ( "Station_ID" int, "Open_Year" int, "Location" text, "Manager_Name" text, "Vice_Manager_Name" text, "Representative_Name" text, PRIMARY KEY ("Station_ID") ) 3 rows from gas_station table: Station_ID Open_Year Location Manager_Name Vice_Manager_Name Representative_Name 1 1998 Herne Hill BrianWingrave Russell Denman Clive Burr 2 1999 Channel Hill SimonMarloe Russell Brown Rob Jefferies 3 2000 Reading North Simon Cope Derek Marloe James Colin Dave Edwards Roger CREATE TABLE "station_company" ( "Station_ID" int, "Company_ID" int, "Rank_of_the_Year" int, PRIMARY KEY ("Station_ID","Company_ID"), FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`), FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`) ) 3 rows from station_company table: Station_ID Company_ID Rank_of_the_Year 11 1 1 1 3 2 6 6 3
gas_company
Show all company names and headquarters in the descending order of market value.
SELECT company , headquarters FROM company ORDER BY market_value DESC
CREATE TABLE "company" ( "Company_ID" int, "Rank" int, "Company" text, "Headquarters" text, "Main_Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value" real, PRIMARY KEY ("Company_ID") ) 3 rows from company table: Company_ID Rank Company Headquarters Main_Industry Sales_billion Profits_billion Assets_billion Market_Value 1 1 ExxonMobil USA Oil and gas 433.5 41.1 331.1 407.4 2 3 General Electric USA Conglomerate 147.3 14.2 717.2 213.7 3 4 Royal Dutch Shell Netherlands Oil and gas 470.2 30.9 340.5 227.6 CREATE TABLE "gas_station" ( "Station_ID" int, "Open_Year" int, "Location" text, "Manager_Name" text, "Vice_Manager_Name" text, "Representative_Name" text, PRIMARY KEY ("Station_ID") ) 3 rows from gas_station table: Station_ID Open_Year Location Manager_Name Vice_Manager_Name Representative_Name 1 1998 Herne Hill BrianWingrave Russell Denman Clive Burr 2 1999 Channel Hill SimonMarloe Russell Brown Rob Jefferies 3 2000 Reading North Simon Cope Derek Marloe James Colin Dave Edwards Roger CREATE TABLE "station_company" ( "Station_ID" int, "Company_ID" int, "Rank_of_the_Year" int, PRIMARY KEY ("Station_ID","Company_ID"), FOREIGN KEY (`Station_ID`) REFERENCES `gas_station`(`Station_ID`), FOREIGN KEY (`Company_ID`) REFERENCES `company`(`Company_ID`) ) 3 rows from station_company table: Station_ID Company_ID Rank_of_the_Year 11 1 1 1 3 2 6 6 3