spider_version
int64
1
2
db_id
stringclasses
204 values
schema
stringclasses
187 values
question
stringlengths
3
328
query
stringlengths
20
3.81k
1
local_govt_mdm
CREATE TABLE Customer_Master_Index ( master_customer_id INTEGER NOT NULL, cmi_details VARCHAR(255), PRIMARY KEY (master_customer_id) ); CREATE TABLE CMI_Cross_References ( cmi_cross_ref_id INTEGER NOT NULL, master_customer_id INTEGER NOT NULL, source_system_code CHAR(15) NOT NULL, PRIMARY KEY (cmi_cross_ref_id), FOREIGN KEY (master_customer_id) REFERENCES Customer_Master_Index (master_customer_id) ); CREATE TABLE Council_Tax ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Business_Rates ( business_rates_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (business_rates_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Benefits_Overpayments ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Parking_Fines ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Rent_Arrears ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Electoral_Register ( electoral_register_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (electoral_register_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) )
What are the register ids of electoral registries that have the cross reference source system code 'Electoral' or 'Tax'?
SELECT T1.electoral_register_id FROM Electoral_Register AS T1 JOIN CMI_Cross_References AS T2 ON T1.cmi_cross_ref_id = T2.cmi_cross_ref_id WHERE T2.source_system_code = 'Electoral' OR T2.source_system_code = 'Tax'
1
local_govt_mdm
CREATE TABLE Customer_Master_Index ( master_customer_id INTEGER NOT NULL, cmi_details VARCHAR(255), PRIMARY KEY (master_customer_id) ); CREATE TABLE CMI_Cross_References ( cmi_cross_ref_id INTEGER NOT NULL, master_customer_id INTEGER NOT NULL, source_system_code CHAR(15) NOT NULL, PRIMARY KEY (cmi_cross_ref_id), FOREIGN KEY (master_customer_id) REFERENCES Customer_Master_Index (master_customer_id) ); CREATE TABLE Council_Tax ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Business_Rates ( business_rates_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (business_rates_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Benefits_Overpayments ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Parking_Fines ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Rent_Arrears ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Electoral_Register ( electoral_register_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (electoral_register_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) )
How many different source system code for the cmi cross references are there?
SELECT count(DISTINCT source_system_code) FROM CMI_cross_references
1
local_govt_mdm
CREATE TABLE Customer_Master_Index ( master_customer_id INTEGER NOT NULL, cmi_details VARCHAR(255), PRIMARY KEY (master_customer_id) ); CREATE TABLE CMI_Cross_References ( cmi_cross_ref_id INTEGER NOT NULL, master_customer_id INTEGER NOT NULL, source_system_code CHAR(15) NOT NULL, PRIMARY KEY (cmi_cross_ref_id), FOREIGN KEY (master_customer_id) REFERENCES Customer_Master_Index (master_customer_id) ); CREATE TABLE Council_Tax ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Business_Rates ( business_rates_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (business_rates_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Benefits_Overpayments ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Parking_Fines ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Rent_Arrears ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Electoral_Register ( electoral_register_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (electoral_register_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) )
List all information about customer master index, and sort them by details in descending order.
SELECT * FROM customer_master_index ORDER BY cmi_details DESC
1
local_govt_mdm
CREATE TABLE Customer_Master_Index ( master_customer_id INTEGER NOT NULL, cmi_details VARCHAR(255), PRIMARY KEY (master_customer_id) ); CREATE TABLE CMI_Cross_References ( cmi_cross_ref_id INTEGER NOT NULL, master_customer_id INTEGER NOT NULL, source_system_code CHAR(15) NOT NULL, PRIMARY KEY (cmi_cross_ref_id), FOREIGN KEY (master_customer_id) REFERENCES Customer_Master_Index (master_customer_id) ); CREATE TABLE Council_Tax ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Business_Rates ( business_rates_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (business_rates_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Benefits_Overpayments ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Parking_Fines ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Rent_Arrears ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Electoral_Register ( electoral_register_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (electoral_register_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) )
List the council tax ids and their related cmi cross references of all the parking fines.
SELECT council_tax_id , cmi_cross_ref_id FROM parking_fines
1
local_govt_mdm
CREATE TABLE Customer_Master_Index ( master_customer_id INTEGER NOT NULL, cmi_details VARCHAR(255), PRIMARY KEY (master_customer_id) ); CREATE TABLE CMI_Cross_References ( cmi_cross_ref_id INTEGER NOT NULL, master_customer_id INTEGER NOT NULL, source_system_code CHAR(15) NOT NULL, PRIMARY KEY (cmi_cross_ref_id), FOREIGN KEY (master_customer_id) REFERENCES Customer_Master_Index (master_customer_id) ); CREATE TABLE Council_Tax ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Business_Rates ( business_rates_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (business_rates_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Benefits_Overpayments ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Parking_Fines ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Rent_Arrears ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Electoral_Register ( electoral_register_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (electoral_register_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) )
How many council taxes are collected for renting arrears ?
SELECT count(*) FROM rent_arrears
1
local_govt_mdm
CREATE TABLE Customer_Master_Index ( master_customer_id INTEGER NOT NULL, cmi_details VARCHAR(255), PRIMARY KEY (master_customer_id) ); CREATE TABLE CMI_Cross_References ( cmi_cross_ref_id INTEGER NOT NULL, master_customer_id INTEGER NOT NULL, source_system_code CHAR(15) NOT NULL, PRIMARY KEY (cmi_cross_ref_id), FOREIGN KEY (master_customer_id) REFERENCES Customer_Master_Index (master_customer_id) ); CREATE TABLE Council_Tax ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Business_Rates ( business_rates_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (business_rates_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Benefits_Overpayments ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Parking_Fines ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Rent_Arrears ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Electoral_Register ( electoral_register_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (electoral_register_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) )
What are the distinct cross reference source system codes which are related to the master customer details 'Gottlieb, Becker and Wyman'?
SELECT DISTINCT T2.source_system_code FROM customer_master_index AS T1 JOIN cmi_cross_references AS T2 ON T1.master_customer_id = T2.master_customer_id WHERE T1.cmi_details = 'Gottlieb , Becker and Wyman'
1
local_govt_mdm
CREATE TABLE Customer_Master_Index ( master_customer_id INTEGER NOT NULL, cmi_details VARCHAR(255), PRIMARY KEY (master_customer_id) ); CREATE TABLE CMI_Cross_References ( cmi_cross_ref_id INTEGER NOT NULL, master_customer_id INTEGER NOT NULL, source_system_code CHAR(15) NOT NULL, PRIMARY KEY (cmi_cross_ref_id), FOREIGN KEY (master_customer_id) REFERENCES Customer_Master_Index (master_customer_id) ); CREATE TABLE Council_Tax ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Business_Rates ( business_rates_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (business_rates_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Benefits_Overpayments ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Parking_Fines ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Rent_Arrears ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Electoral_Register ( electoral_register_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (electoral_register_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) )
Which cmi cross reference id is not related to any parking taxes?
SELECT cmi_cross_ref_id FROM cmi_cross_references EXCEPT SELECT cmi_cross_ref_id FROM parking_fines
1
local_govt_mdm
CREATE TABLE Customer_Master_Index ( master_customer_id INTEGER NOT NULL, cmi_details VARCHAR(255), PRIMARY KEY (master_customer_id) ); CREATE TABLE CMI_Cross_References ( cmi_cross_ref_id INTEGER NOT NULL, master_customer_id INTEGER NOT NULL, source_system_code CHAR(15) NOT NULL, PRIMARY KEY (cmi_cross_ref_id), FOREIGN KEY (master_customer_id) REFERENCES Customer_Master_Index (master_customer_id) ); CREATE TABLE Council_Tax ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Business_Rates ( business_rates_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (business_rates_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Benefits_Overpayments ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Parking_Fines ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Rent_Arrears ( council_tax_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (council_tax_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) ); CREATE TABLE Electoral_Register ( electoral_register_id INTEGER NOT NULL, cmi_cross_ref_id INTEGER NOT NULL, PRIMARY KEY (electoral_register_id), FOREIGN KEY (cmi_cross_ref_id) REFERENCES CMI_Cross_References (cmi_cross_ref_id) )
Which distinct source system code includes the substring 'en'?
SELECT DISTINCT source_system_code FROM cmi_cross_references WHERE source_system_code LIKE '%en%'
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
How many parties are there?
SELECT count(*) FROM party
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
Count the number of parties.
SELECT count(*) FROM party
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
List the themes of parties in ascending order of number of hosts.
SELECT Party_Theme FROM party ORDER BY Number_of_hosts ASC
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
What are the themes of parties ordered by the number of hosts in ascending manner?
SELECT Party_Theme FROM party ORDER BY Number_of_hosts ASC
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
What are the themes and locations of parties?
SELECT Party_Theme , LOCATION FROM party
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
Give me the theme and location of each party.
SELECT Party_Theme , LOCATION FROM party
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
Show the first year and last year of parties with theme "Spring" or "Teqnology".
SELECT First_year , Last_year FROM party WHERE Party_Theme = "Spring" OR Party_Theme = "Teqnology"
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
What are the first year and last year of the parties whose theme is "Spring" or "Teqnology"?
SELECT First_year , Last_year FROM party WHERE Party_Theme = "Spring" OR Party_Theme = "Teqnology"
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
What is the average number of hosts for parties?
SELECT avg(Number_of_hosts) FROM party
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
Compute the average number of hosts for parties.
SELECT avg(Number_of_hosts) FROM party
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
What is the location of the party with the most hosts?
SELECT LOCATION FROM party ORDER BY Number_of_hosts DESC LIMIT 1
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
Which party had the most hosts? Give me the party location.
SELECT LOCATION FROM party ORDER BY Number_of_hosts DESC LIMIT 1
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
Show different nationalities along with the number of hosts of each nationality.
SELECT Nationality , COUNT(*) FROM HOST GROUP BY Nationality
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
How many hosts does each nationality have? List the nationality and the count.
SELECT Nationality , COUNT(*) FROM HOST GROUP BY Nationality
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
Show the most common nationality of hosts.
SELECT Nationality FROM HOST GROUP BY Nationality ORDER BY COUNT(*) DESC LIMIT 1
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
Which nationality has the most hosts?
SELECT Nationality FROM HOST GROUP BY Nationality ORDER BY COUNT(*) DESC LIMIT 1
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
Show the nations that have both hosts older than 45 and hosts younger than 35.
SELECT Nationality FROM HOST WHERE Age > 45 INTERSECT SELECT Nationality FROM HOST WHERE Age < 35
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
Which nations have both hosts of age above 45 and hosts of age below 35?
SELECT Nationality FROM HOST WHERE Age > 45 INTERSECT SELECT Nationality FROM HOST WHERE Age < 35
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
Show the themes of parties and the names of the party hosts.
SELECT T3.Party_Theme , T2.Name FROM party_host AS T1 JOIN HOST AS T2 ON T1.Host_ID = T2.Host_ID JOIN party AS T3 ON T1.Party_ID = T3.Party_ID
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
For each party, return its theme and the name of its host.
SELECT T3.Party_Theme , T2.Name FROM party_host AS T1 JOIN HOST AS T2 ON T1.Host_ID = T2.Host_ID JOIN party AS T3 ON T1.Party_ID = T3.Party_ID
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
Show the locations of parties and the names of the party hosts in ascending order of the age of the host.
SELECT T3.Location , T2.Name FROM party_host AS T1 JOIN HOST AS T2 ON T1.Host_ID = T2.Host_ID JOIN party AS T3 ON T1.Party_ID = T3.Party_ID ORDER BY T2.Age
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
For each party, find its location and the name of its host. Sort the result in ascending order of the age of the host.
SELECT T3.Location , T2.Name FROM party_host AS T1 JOIN HOST AS T2 ON T1.Host_ID = T2.Host_ID JOIN party AS T3 ON T1.Party_ID = T3.Party_ID ORDER BY T2.Age
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
Show the locations of parties with hosts older than 50.
SELECT T3.Location FROM party_host AS T1 JOIN HOST AS T2 ON T1.Host_ID = T2.Host_ID JOIN party AS T3 ON T1.Party_ID = T3.Party_ID WHERE T2.Age > 50
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
Which parties have hosts of age above 50? Give me the party locations.
SELECT T3.Location FROM party_host AS T1 JOIN HOST AS T2 ON T1.Host_ID = T2.Host_ID JOIN party AS T3 ON T1.Party_ID = T3.Party_ID WHERE T2.Age > 50
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
Show the host names for parties with number of hosts greater than 20.
SELECT T2.Name FROM party_host AS T1 JOIN HOST AS T2 ON T1.Host_ID = T2.Host_ID JOIN party AS T3 ON T1.Party_ID = T3.Party_ID WHERE T3.Number_of_hosts > 20
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
Which parties have more than 20 hosts? Give me the host names for these parties.
SELECT T2.Name FROM party_host AS T1 JOIN HOST AS T2 ON T1.Host_ID = T2.Host_ID JOIN party AS T3 ON T1.Party_ID = T3.Party_ID WHERE T3.Number_of_hosts > 20
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
Show the name and the nationality of the oldest host.
SELECT Name , Nationality FROM HOST ORDER BY Age DESC LIMIT 1
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
What are the name and the nationality of the host of the highest age?
SELECT Name , Nationality FROM HOST ORDER BY Age DESC LIMIT 1
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
List the names of hosts who did not serve as a host of any party in our record.
SELECT Name FROM HOST WHERE Host_ID NOT IN (SELECT Host_ID FROM party_host)
1
party_host
CREATE TABLE "party" ( "Party_ID" int, "Party_Theme" text, "Location" text, "First_year" text, "Last_year" text, "Number_of_hosts" int, PRIMARY KEY ("Party_ID") ); CREATE TABLE "host" ( "Host_ID" int, "Name" text, "Nationality" text, "Age" text, PRIMARY KEY ("Host_ID") ); CREATE TABLE "party_host" ( "Party_ID" int, "Host_ID" int, "Is_Main_in_Charge" bool, PRIMARY KEY ("Party_ID","Host_ID"), FOREIGN KEY ("Host_ID") REFERENCES `host`("Host_ID"), FOREIGN KEY ("Party_ID") REFERENCES `party`("Party_ID") )
What are the names of hosts who did not host any party in our record?
SELECT Name FROM HOST WHERE Host_ID NOT IN (SELECT Host_ID FROM party_host)
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
How many regions do we have?
SELECT count(*) FROM region
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
Count the number of regions.
SELECT count(*) FROM region
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
Show all region code and region name sorted by the codes.
SELECT region_code , region_name FROM region ORDER BY region_code
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
What are the codes and names for all regions, sorted by codes?
SELECT region_code , region_name FROM region ORDER BY region_code
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
List all region names in alphabetical order.
SELECT region_name FROM region ORDER BY region_name
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
What are the names of the regions in alphabetical order?
SELECT region_name FROM region ORDER BY region_name
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
Show names for all regions except for Denmark.
SELECT region_name FROM region WHERE region_name != 'Denmark'
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
Return the names of all regions other than Denmark.
SELECT region_name FROM region WHERE region_name != 'Denmark'
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
How many storms had death records?
SELECT count(*) FROM storm WHERE Number_Deaths > 0
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
Count the number of storms in which at least 1 person died.
SELECT count(*) FROM storm WHERE Number_Deaths > 0
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
List name, dates active, and number of deaths for all storms with at least 1 death.
SELECT name , dates_active , number_deaths FROM storm WHERE number_deaths >= 1
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
What are the names, dates active, and number of deaths for storms that had 1 or more death?
SELECT name , dates_active , number_deaths FROM storm WHERE number_deaths >= 1
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
Show the average and maximum damage for all storms with max speed higher than 1000.
SELECT avg(damage_millions_USD) , max(damage_millions_USD) FROM storm WHERE max_speed > 1000
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
What is the average and maximum damage in millions for storms that had a max speed over 1000?
SELECT avg(damage_millions_USD) , max(damage_millions_USD) FROM storm WHERE max_speed > 1000
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
What is the total number of deaths and damage for all storms with a max speed greater than the average?
SELECT sum(number_deaths) , sum(damage_millions_USD) FROM storm WHERE max_speed > (SELECT avg(max_speed) FROM storm)
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
Return the total number of deaths and total damange in millions for storms that had a max speed greater than the average.
SELECT sum(number_deaths) , sum(damage_millions_USD) FROM storm WHERE max_speed > (SELECT avg(max_speed) FROM storm)
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
List name and damage for all storms in a descending order of max speed.
SELECT name , damage_millions_USD FROM storm ORDER BY max_speed DESC
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
What are the names and damage in millions for storms, ordered by their max speeds descending?
SELECT name , damage_millions_USD FROM storm ORDER BY max_speed DESC
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
How many regions are affected?
SELECT count(DISTINCT region_id) FROM affected_region
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
Count the number of different affected regions.
SELECT count(DISTINCT region_id) FROM affected_region
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
Show the name for regions not affected.
SELECT region_name FROM region WHERE region_id NOT IN (SELECT region_id FROM affected_region)
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
What are the names of regions that were not affected?
SELECT region_name FROM region WHERE region_id NOT IN (SELECT region_id FROM affected_region)
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
Show the name for regions and the number of storms for each region.
SELECT T1.region_name , count(*) FROM region AS T1 JOIN affected_region AS T2 ON T1.region_id = T2.region_id GROUP BY T1.region_id
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
How many storms occured in each region?
SELECT T1.region_name , count(*) FROM region AS T1 JOIN affected_region AS T2 ON T1.region_id = T2.region_id GROUP BY T1.region_id
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
List the name for storms and the number of affected regions for each storm.
SELECT T1.name , count(*) FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id = T2.storm_id GROUP BY T1.storm_id
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
How many regions were affected by each storm?
SELECT T1.name , count(*) FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id = T2.storm_id GROUP BY T1.storm_id
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
What is the storm name and max speed which affected the greatest number of regions?
SELECT T1.name , T1.max_speed FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id = T2.storm_id GROUP BY T1.storm_id ORDER BY count(*) DESC LIMIT 1
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
Return the name and max speed of the storm that affected the most regions.
SELECT T1.name , T1.max_speed FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id = T2.storm_id GROUP BY T1.storm_id ORDER BY count(*) DESC LIMIT 1
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
Show the name of storms which don't have affected region in record.
SELECT name FROM storm WHERE storm_id NOT IN (SELECT storm_id FROM affected_region)
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
What are the names of storms that did not affect any regions?
SELECT name FROM storm WHERE storm_id NOT IN (SELECT storm_id FROM affected_region)
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
Show storm name with at least two regions and 10 cities affected.
SELECT T1.name FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id = T2.storm_id GROUP BY T1.storm_id HAVING count(*) >= 2 INTERSECT SELECT T1.name FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id = T2.storm_id GROUP BY T1.storm_id HAVING sum(T2.number_city_affected) >= 10
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
What are the names of storms that both affected two or more regions and affected a total of 10 or more cities?
SELECT T1.name FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id = T2.storm_id GROUP BY T1.storm_id HAVING count(*) >= 2 INTERSECT SELECT T1.name FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id = T2.storm_id GROUP BY T1.storm_id HAVING sum(T2.number_city_affected) >= 10
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
Show all storm names except for those with at least two affected regions.
SELECT name FROM storm EXCEPT SELECT T1.name FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id = T2.storm_id GROUP BY T1.storm_id HAVING count(*) >= 2
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
What are the names of storms that did not affect two or more regions?
SELECT name FROM storm EXCEPT SELECT T1.name FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id = T2.storm_id GROUP BY T1.storm_id HAVING count(*) >= 2
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
What are the region names affected by the storm with a number of deaths of least 10?
SELECT T2.region_name FROM affected_region AS T1 JOIN region AS T2 ON T1.region_id = T2.region_id JOIN storm AS T3 ON T1.storm_id = T3.storm_id WHERE T3.number_deaths >= 10
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
Return the names of the regions affected by storms that had a death count of at least 10.
SELECT T2.region_name FROM affected_region AS T1 JOIN region AS T2 ON T1.region_id = T2.region_id JOIN storm AS T3 ON T1.storm_id = T3.storm_id WHERE T3.number_deaths >= 10
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
Show all storm names affecting region "Denmark".
SELECT T3.name FROM affected_region AS T1 JOIN region AS T2 ON T1.region_id = T2.region_id JOIN storm AS T3 ON T1.storm_id = T3.storm_id WHERE T2.region_name = 'Denmark'
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
What are the names of the storms that affected Denmark?
SELECT T3.name FROM affected_region AS T1 JOIN region AS T2 ON T1.region_id = T2.region_id JOIN storm AS T3 ON T1.storm_id = T3.storm_id WHERE T2.region_name = 'Denmark'
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
Show the region name with at least two storms.
SELECT T1.region_name FROM region AS T1 JOIN affected_region AS T2 ON T1.region_id = T2.region_id GROUP BY T1.region_id HAVING count(*) >= 2
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
What are the names of regions with two or more storms?
SELECT T1.region_name FROM region AS T1 JOIN affected_region AS T2 ON T1.region_id = T2.region_id GROUP BY T1.region_id HAVING count(*) >= 2
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
Find the names of the regions which were affected by the storm that killed the greatest number of people.
SELECT T2.region_name FROM affected_region AS T1 JOIN region AS T2 ON T1.region_id = T2.region_id JOIN storm AS T3 ON T1.storm_id = T3.storm_id ORDER BY T3.Number_Deaths DESC LIMIT 1
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
What are the names of regions that were affected by the storm in which the most people died?
SELECT T2.region_name FROM affected_region AS T1 JOIN region AS T2 ON T1.region_id = T2.region_id JOIN storm AS T3 ON T1.storm_id = T3.storm_id ORDER BY T3.Number_Deaths DESC LIMIT 1
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
Find the name of the storm that affected both Afghanistan and Albania regions.
SELECT T3.Name FROM affected_region AS T1 JOIN region AS T2 ON T1.region_id = T2.region_id JOIN storm AS T3 ON T1.storm_id = T3.storm_id WHERE T2.Region_name = 'Afghanistan' INTERSECT SELECT T3.Name FROM affected_region AS T1 JOIN region AS T2 ON T1.region_id = T2.region_id JOIN storm AS T3 ON T1.storm_id = T3.storm_id WHERE T2.Region_name = 'Albania'
1
storm_record
CREATE TABLE "storm" ( "Storm_ID" int, "Name" text, "Dates_active" text, "Max_speed" int, "Damage_millions_USD" real, "Number_Deaths" int, PRIMARY KEY ("Storm_ID") ); CREATE TABLE "region" ( `Region_id` int, `Region_code` text, `Region_name` text, PRIMARY KEY ("Region_id") ); CREATE TABLE `affected_region` ( `Region_id` int, `Storm_ID` int, `Number_city_affected` real, PRIMARY KEY (`Region_id`,`Storm_ID`), FOREIGN KEY (`Region_id`) REFERENCES `region`(`Region_id`), FOREIGN KEY (`Storm_ID`) REFERENCES `storm`(`Storm_ID`) )
What are the names of the storms that affected both the regions of Afghanistan and Albania?
SELECT T3.Name FROM affected_region AS T1 JOIN region AS T2 ON T1.region_id = T2.region_id JOIN storm AS T3 ON T1.storm_id = T3.storm_id WHERE T2.Region_name = 'Afghanistan' INTERSECT SELECT T3.Name FROM affected_region AS T1 JOIN region AS T2 ON T1.region_id = T2.region_id JOIN storm AS T3 ON T1.storm_id = T3.storm_id WHERE T2.Region_name = 'Albania'
1
election
CREATE TABLE "county" ( "County_Id" int, "County_name" text, "Population" real, "Zip_code" text, PRIMARY KEY ("County_Id") ); CREATE TABLE "party" ( "Party_ID" int, "Year" real, "Party" text, "Governor" text, "Lieutenant_Governor" text, "Comptroller" text, "Attorney_General" text, "US_Senate" text, PRIMARY KEY ("Party_ID") ); CREATE TABLE "election" ( "Election_ID" int, "Counties_Represented" text, "District" int, "Delegate" text, "Party" int, "First_Elected" real, "Committee" text, PRIMARY KEY ("Election_ID"), FOREIGN KEY (`Party`) REFERENCES `party`(`Party_ID`), FOREIGN KEY (`District`) REFERENCES `county`(`County_Id`) )
How many counties are there in total?
SELECT count(*) FROM county
1
election
CREATE TABLE "county" ( "County_Id" int, "County_name" text, "Population" real, "Zip_code" text, PRIMARY KEY ("County_Id") ); CREATE TABLE "party" ( "Party_ID" int, "Year" real, "Party" text, "Governor" text, "Lieutenant_Governor" text, "Comptroller" text, "Attorney_General" text, "US_Senate" text, PRIMARY KEY ("Party_ID") ); CREATE TABLE "election" ( "Election_ID" int, "Counties_Represented" text, "District" int, "Delegate" text, "Party" int, "First_Elected" real, "Committee" text, PRIMARY KEY ("Election_ID"), FOREIGN KEY (`Party`) REFERENCES `party`(`Party_ID`), FOREIGN KEY (`District`) REFERENCES `county`(`County_Id`) )
Count the total number of counties.
SELECT count(*) FROM county
1
election
CREATE TABLE "county" ( "County_Id" int, "County_name" text, "Population" real, "Zip_code" text, PRIMARY KEY ("County_Id") ); CREATE TABLE "party" ( "Party_ID" int, "Year" real, "Party" text, "Governor" text, "Lieutenant_Governor" text, "Comptroller" text, "Attorney_General" text, "US_Senate" text, PRIMARY KEY ("Party_ID") ); CREATE TABLE "election" ( "Election_ID" int, "Counties_Represented" text, "District" int, "Delegate" text, "Party" int, "First_Elected" real, "Committee" text, PRIMARY KEY ("Election_ID"), FOREIGN KEY (`Party`) REFERENCES `party`(`Party_ID`), FOREIGN KEY (`District`) REFERENCES `county`(`County_Id`) )
Show the county name and population of all counties.
SELECT County_name , Population FROM county
1
election
CREATE TABLE "county" ( "County_Id" int, "County_name" text, "Population" real, "Zip_code" text, PRIMARY KEY ("County_Id") ); CREATE TABLE "party" ( "Party_ID" int, "Year" real, "Party" text, "Governor" text, "Lieutenant_Governor" text, "Comptroller" text, "Attorney_General" text, "US_Senate" text, PRIMARY KEY ("Party_ID") ); CREATE TABLE "election" ( "Election_ID" int, "Counties_Represented" text, "District" int, "Delegate" text, "Party" int, "First_Elected" real, "Committee" text, PRIMARY KEY ("Election_ID"), FOREIGN KEY (`Party`) REFERENCES `party`(`Party_ID`), FOREIGN KEY (`District`) REFERENCES `county`(`County_Id`) )
What are the name and population of each county?
SELECT County_name , Population FROM county
1
election
CREATE TABLE "county" ( "County_Id" int, "County_name" text, "Population" real, "Zip_code" text, PRIMARY KEY ("County_Id") ); CREATE TABLE "party" ( "Party_ID" int, "Year" real, "Party" text, "Governor" text, "Lieutenant_Governor" text, "Comptroller" text, "Attorney_General" text, "US_Senate" text, PRIMARY KEY ("Party_ID") ); CREATE TABLE "election" ( "Election_ID" int, "Counties_Represented" text, "District" int, "Delegate" text, "Party" int, "First_Elected" real, "Committee" text, PRIMARY KEY ("Election_ID"), FOREIGN KEY (`Party`) REFERENCES `party`(`Party_ID`), FOREIGN KEY (`District`) REFERENCES `county`(`County_Id`) )
Show the average population of all counties.
SELECT avg(Population) FROM county
1
election
CREATE TABLE "county" ( "County_Id" int, "County_name" text, "Population" real, "Zip_code" text, PRIMARY KEY ("County_Id") ); CREATE TABLE "party" ( "Party_ID" int, "Year" real, "Party" text, "Governor" text, "Lieutenant_Governor" text, "Comptroller" text, "Attorney_General" text, "US_Senate" text, PRIMARY KEY ("Party_ID") ); CREATE TABLE "election" ( "Election_ID" int, "Counties_Represented" text, "District" int, "Delegate" text, "Party" int, "First_Elected" real, "Committee" text, PRIMARY KEY ("Election_ID"), FOREIGN KEY (`Party`) REFERENCES `party`(`Party_ID`), FOREIGN KEY (`District`) REFERENCES `county`(`County_Id`) )
On average how large is the population of the counties?
SELECT avg(Population) FROM county
1
election
CREATE TABLE "county" ( "County_Id" int, "County_name" text, "Population" real, "Zip_code" text, PRIMARY KEY ("County_Id") ); CREATE TABLE "party" ( "Party_ID" int, "Year" real, "Party" text, "Governor" text, "Lieutenant_Governor" text, "Comptroller" text, "Attorney_General" text, "US_Senate" text, PRIMARY KEY ("Party_ID") ); CREATE TABLE "election" ( "Election_ID" int, "Counties_Represented" text, "District" int, "Delegate" text, "Party" int, "First_Elected" real, "Committee" text, PRIMARY KEY ("Election_ID"), FOREIGN KEY (`Party`) REFERENCES `party`(`Party_ID`), FOREIGN KEY (`District`) REFERENCES `county`(`County_Id`) )
Return the maximum and minimum population among all counties.
SELECT max(Population) , min(Population) FROM county
1
election
CREATE TABLE "county" ( "County_Id" int, "County_name" text, "Population" real, "Zip_code" text, PRIMARY KEY ("County_Id") ); CREATE TABLE "party" ( "Party_ID" int, "Year" real, "Party" text, "Governor" text, "Lieutenant_Governor" text, "Comptroller" text, "Attorney_General" text, "US_Senate" text, PRIMARY KEY ("Party_ID") ); CREATE TABLE "election" ( "Election_ID" int, "Counties_Represented" text, "District" int, "Delegate" text, "Party" int, "First_Elected" real, "Committee" text, PRIMARY KEY ("Election_ID"), FOREIGN KEY (`Party`) REFERENCES `party`(`Party_ID`), FOREIGN KEY (`District`) REFERENCES `county`(`County_Id`) )
What are the maximum and minimum population of the counties?
SELECT max(Population) , min(Population) FROM county
1
election
CREATE TABLE "county" ( "County_Id" int, "County_name" text, "Population" real, "Zip_code" text, PRIMARY KEY ("County_Id") ); CREATE TABLE "party" ( "Party_ID" int, "Year" real, "Party" text, "Governor" text, "Lieutenant_Governor" text, "Comptroller" text, "Attorney_General" text, "US_Senate" text, PRIMARY KEY ("Party_ID") ); CREATE TABLE "election" ( "Election_ID" int, "Counties_Represented" text, "District" int, "Delegate" text, "Party" int, "First_Elected" real, "Committee" text, PRIMARY KEY ("Election_ID"), FOREIGN KEY (`Party`) REFERENCES `party`(`Party_ID`), FOREIGN KEY (`District`) REFERENCES `county`(`County_Id`) )
Show all the distinct districts for elections.
SELECT DISTINCT District FROM election
1
election
CREATE TABLE "county" ( "County_Id" int, "County_name" text, "Population" real, "Zip_code" text, PRIMARY KEY ("County_Id") ); CREATE TABLE "party" ( "Party_ID" int, "Year" real, "Party" text, "Governor" text, "Lieutenant_Governor" text, "Comptroller" text, "Attorney_General" text, "US_Senate" text, PRIMARY KEY ("Party_ID") ); CREATE TABLE "election" ( "Election_ID" int, "Counties_Represented" text, "District" int, "Delegate" text, "Party" int, "First_Elected" real, "Committee" text, PRIMARY KEY ("Election_ID"), FOREIGN KEY (`Party`) REFERENCES `party`(`Party_ID`), FOREIGN KEY (`District`) REFERENCES `county`(`County_Id`) )
What are the distinct districts for elections?
SELECT DISTINCT District FROM election
1
election
CREATE TABLE "county" ( "County_Id" int, "County_name" text, "Population" real, "Zip_code" text, PRIMARY KEY ("County_Id") ); CREATE TABLE "party" ( "Party_ID" int, "Year" real, "Party" text, "Governor" text, "Lieutenant_Governor" text, "Comptroller" text, "Attorney_General" text, "US_Senate" text, PRIMARY KEY ("Party_ID") ); CREATE TABLE "election" ( "Election_ID" int, "Counties_Represented" text, "District" int, "Delegate" text, "Party" int, "First_Elected" real, "Committee" text, PRIMARY KEY ("Election_ID"), FOREIGN KEY (`Party`) REFERENCES `party`(`Party_ID`), FOREIGN KEY (`District`) REFERENCES `county`(`County_Id`) )
Show the zip code of the county with name "Howard".
SELECT Zip_code FROM county WHERE County_name = "Howard"
1
election
CREATE TABLE "county" ( "County_Id" int, "County_name" text, "Population" real, "Zip_code" text, PRIMARY KEY ("County_Id") ); CREATE TABLE "party" ( "Party_ID" int, "Year" real, "Party" text, "Governor" text, "Lieutenant_Governor" text, "Comptroller" text, "Attorney_General" text, "US_Senate" text, PRIMARY KEY ("Party_ID") ); CREATE TABLE "election" ( "Election_ID" int, "Counties_Represented" text, "District" int, "Delegate" text, "Party" int, "First_Elected" real, "Committee" text, PRIMARY KEY ("Election_ID"), FOREIGN KEY (`Party`) REFERENCES `party`(`Party_ID`), FOREIGN KEY (`District`) REFERENCES `county`(`County_Id`) )
What is the zip code the county named "Howard" is located in?
SELECT Zip_code FROM county WHERE County_name = "Howard"
1
election
CREATE TABLE "county" ( "County_Id" int, "County_name" text, "Population" real, "Zip_code" text, PRIMARY KEY ("County_Id") ); CREATE TABLE "party" ( "Party_ID" int, "Year" real, "Party" text, "Governor" text, "Lieutenant_Governor" text, "Comptroller" text, "Attorney_General" text, "US_Senate" text, PRIMARY KEY ("Party_ID") ); CREATE TABLE "election" ( "Election_ID" int, "Counties_Represented" text, "District" int, "Delegate" text, "Party" int, "First_Elected" real, "Committee" text, PRIMARY KEY ("Election_ID"), FOREIGN KEY (`Party`) REFERENCES `party`(`Party_ID`), FOREIGN KEY (`District`) REFERENCES `county`(`County_Id`) )
Show the delegate from district 1 in election.
SELECT Delegate FROM election WHERE District = 1
1
election
CREATE TABLE "county" ( "County_Id" int, "County_name" text, "Population" real, "Zip_code" text, PRIMARY KEY ("County_Id") ); CREATE TABLE "party" ( "Party_ID" int, "Year" real, "Party" text, "Governor" text, "Lieutenant_Governor" text, "Comptroller" text, "Attorney_General" text, "US_Senate" text, PRIMARY KEY ("Party_ID") ); CREATE TABLE "election" ( "Election_ID" int, "Counties_Represented" text, "District" int, "Delegate" text, "Party" int, "First_Elected" real, "Committee" text, PRIMARY KEY ("Election_ID"), FOREIGN KEY (`Party`) REFERENCES `party`(`Party_ID`), FOREIGN KEY (`District`) REFERENCES `county`(`County_Id`) )
Who is the delegate of district 1 in the elections?
SELECT Delegate FROM election WHERE District = 1
1
election
CREATE TABLE "county" ( "County_Id" int, "County_name" text, "Population" real, "Zip_code" text, PRIMARY KEY ("County_Id") ); CREATE TABLE "party" ( "Party_ID" int, "Year" real, "Party" text, "Governor" text, "Lieutenant_Governor" text, "Comptroller" text, "Attorney_General" text, "US_Senate" text, PRIMARY KEY ("Party_ID") ); CREATE TABLE "election" ( "Election_ID" int, "Counties_Represented" text, "District" int, "Delegate" text, "Party" int, "First_Elected" real, "Committee" text, PRIMARY KEY ("Election_ID"), FOREIGN KEY (`Party`) REFERENCES `party`(`Party_ID`), FOREIGN KEY (`District`) REFERENCES `county`(`County_Id`) )
Show the delegate and committee information of elections.
SELECT Delegate , Committee FROM election
1
election
CREATE TABLE "county" ( "County_Id" int, "County_name" text, "Population" real, "Zip_code" text, PRIMARY KEY ("County_Id") ); CREATE TABLE "party" ( "Party_ID" int, "Year" real, "Party" text, "Governor" text, "Lieutenant_Governor" text, "Comptroller" text, "Attorney_General" text, "US_Senate" text, PRIMARY KEY ("Party_ID") ); CREATE TABLE "election" ( "Election_ID" int, "Counties_Represented" text, "District" int, "Delegate" text, "Party" int, "First_Elected" real, "Committee" text, PRIMARY KEY ("Election_ID"), FOREIGN KEY (`Party`) REFERENCES `party`(`Party_ID`), FOREIGN KEY (`District`) REFERENCES `county`(`County_Id`) )
What are the delegate and committee information for each election record?
SELECT Delegate , Committee FROM election
1
election
CREATE TABLE "county" ( "County_Id" int, "County_name" text, "Population" real, "Zip_code" text, PRIMARY KEY ("County_Id") ); CREATE TABLE "party" ( "Party_ID" int, "Year" real, "Party" text, "Governor" text, "Lieutenant_Governor" text, "Comptroller" text, "Attorney_General" text, "US_Senate" text, PRIMARY KEY ("Party_ID") ); CREATE TABLE "election" ( "Election_ID" int, "Counties_Represented" text, "District" int, "Delegate" text, "Party" int, "First_Elected" real, "Committee" text, PRIMARY KEY ("Election_ID"), FOREIGN KEY (`Party`) REFERENCES `party`(`Party_ID`), FOREIGN KEY (`District`) REFERENCES `county`(`County_Id`) )
How many distinct governors are there?
SELECT count(DISTINCT Governor) FROM party
1
election
CREATE TABLE "county" ( "County_Id" int, "County_name" text, "Population" real, "Zip_code" text, PRIMARY KEY ("County_Id") ); CREATE TABLE "party" ( "Party_ID" int, "Year" real, "Party" text, "Governor" text, "Lieutenant_Governor" text, "Comptroller" text, "Attorney_General" text, "US_Senate" text, PRIMARY KEY ("Party_ID") ); CREATE TABLE "election" ( "Election_ID" int, "Counties_Represented" text, "District" int, "Delegate" text, "Party" int, "First_Elected" real, "Committee" text, PRIMARY KEY ("Election_ID"), FOREIGN KEY (`Party`) REFERENCES `party`(`Party_ID`), FOREIGN KEY (`District`) REFERENCES `county`(`County_Id`) )
Count the number of distinct governors.
SELECT count(DISTINCT Governor) FROM party