spider_version
int64
1
2
db_id
stringclasses
204 values
schema
stringclasses
187 values
question
stringlengths
3
328
query
stringlengths
20
3.81k
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 lieutenant governor and comptroller from the democratic party.
SELECT Lieutenant_Governor , Comptroller FROM party WHERE Party = "Democratic"
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 are the lieutenant governor and comptroller from the democratic party?
SELECT Lieutenant_Governor , Comptroller FROM party WHERE Party = "Democratic"
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`) )
In which distinct years was the governor "Eliot Spitzer"?
SELECT DISTINCT YEAR FROM party WHERE Governor = "Eliot Spitzer"
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`) )
Find the distinct years when the governor was named "Eliot Spitzer".
SELECT DISTINCT YEAR FROM party WHERE Governor = "Eliot Spitzer"
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 information about election.
SELECT * 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`) )
Return all the information for each election record.
SELECT * 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 delegates and the names of county they belong to.
SELECT T2.Delegate , T1.County_name FROM county AS T1 JOIN election AS T2 ON T1.County_id = T2.District
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 name of the county they belong to, for each county?
SELECT T2.Delegate , T1.County_name FROM county AS T1 JOIN election AS T2 ON T1.County_id = T2.District
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`) )
Which delegates are from counties with population smaller than 100000?
SELECT T2.Delegate FROM county AS T1 JOIN election AS T2 ON T1.County_id = T2.District WHERE T1.Population < 100000
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`) )
Find the delegates who are from counties with population below 100000.
SELECT T2.Delegate FROM county AS T1 JOIN election AS T2 ON T1.County_id = T2.District WHERE T1.Population < 100000
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 delegates are from counties with population larger than 50000?
SELECT count(DISTINCT T2.Delegate) FROM county AS T1 JOIN election AS T2 ON T1.County_id = T2.District WHERE T1.Population > 50000
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 delegates who are from counties with population above 50000.
SELECT count(DISTINCT T2.Delegate) FROM county AS T1 JOIN election AS T2 ON T1.County_id = T2.District WHERE T1.Population > 50000
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 names of the county that the delegates on "Appropriations" committee belong to?
SELECT T1.County_name FROM county AS T1 JOIN election AS T2 ON T1.County_id = T2.District WHERE T2.Committee = "Appropriations"
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`) )
Which county do the delegates on "Appropriations" committee belong to? Give me the county names.
SELECT T1.County_name FROM county AS T1 JOIN election AS T2 ON T1.County_id = T2.District WHERE T2.Committee = "Appropriations"
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 delegates and the names of the party they belong to.
SELECT T1.Delegate , T2.Party FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID
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`) )
For each delegate, find the names of the party they are part of.
SELECT T1.Delegate , T2.Party FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID
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 were the governors of the parties associated with delegates from district 1?
SELECT T2.Governor FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T1.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`) )
Find the parties associated with the delegates from district 1. Who served as governors of the parties?
SELECT T2.Governor FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T1.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 were the comptrollers of the parties associated with the delegates from district 1 or district 2?
SELECT T2.Comptroller FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T1.District = 1 OR T1.District = 2
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`) )
Find the parties associated with the delegates from district 1 or 2. Who served as comptrollers of the parties?
SELECT T2.Comptroller FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T1.District = 1 OR T1.District = 2
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 all the committees that have delegates from Democratic party.
SELECT T1.Committee FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T2.Party = "Democratic"
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`) )
Which committees have delegates from the Democratic party?
SELECT T1.Committee FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T2.Party = "Democratic"
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 name of each county along with the corresponding number of delegates from that county.
SELECT T1.County_name , COUNT(*) FROM county AS T1 JOIN election AS T2 ON T1.County_id = T2.District GROUP BY T1.County_id
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`) )
For each county, find the name of the county and the number of delegates from that county.
SELECT T1.County_name , COUNT(*) FROM county AS T1 JOIN election AS T2 ON T1.County_id = T2.District GROUP BY T1.County_id
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 name of each party and the corresponding number of delegates from that party.
SELECT T2.Party , COUNT(*) FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID GROUP BY T1.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`) )
For each party, return the name of the party and the number of delegates from that party.
SELECT T2.Party , COUNT(*) FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID GROUP BY T1.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`) )
Return the names of all counties sorted by population in ascending order.
SELECT County_name FROM county ORDER BY Population ASC
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`) )
Sort the names of all counties in ascending order of population.
SELECT County_name FROM county ORDER BY Population ASC
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 names of all counties sorted by county name in descending alphabetical order.
SELECT County_name FROM county ORDER BY County_name DESC
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`) )
Sort the names of all counties in descending alphabetical order.
SELECT County_name FROM county ORDER BY County_name DESC
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 name of the county with the biggest population.
SELECT County_name FROM county ORDER BY Population DESC LIMIT 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`) )
Which county has the largest population? Give me the name of the county.
SELECT County_name FROM county ORDER BY Population DESC LIMIT 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 3 counties with the smallest population.
SELECT County_name FROM county ORDER BY Population ASC LIMIT 3
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 3 counties that have the smallest population? Give me the county names.
SELECT County_name FROM county ORDER BY Population ASC LIMIT 3
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 names of counties that have at least two delegates.
SELECT T1.County_name FROM county AS T1 JOIN election AS T2 ON T1.County_id = T2.District GROUP BY T1.County_id HAVING COUNT(*) >= 2
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`) )
Which counties have two or more delegates? Give me the county names.
SELECT T1.County_name FROM county AS T1 JOIN election AS T2 ON T1.County_id = T2.District GROUP BY T1.County_id HAVING COUNT(*) >= 2
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 name of the party that has at least two records.
SELECT Party FROM party GROUP BY Party HAVING COUNT(*) >= 2
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`) )
Which party has two or more records?
SELECT Party FROM party GROUP BY Party HAVING COUNT(*) >= 2
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 name of the party that has the most delegates.
SELECT T2.Party FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID GROUP BY T1.Party ORDER BY COUNT(*) DESC LIMIT 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`) )
Which party has the largest number of delegates?
SELECT T2.Party FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID GROUP BY T1.Party ORDER BY COUNT(*) DESC LIMIT 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 people that have been governor the most times.
SELECT Governor FROM party GROUP BY Governor ORDER BY COUNT(*) DESC LIMIT 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`) )
Which people severed as governor most frequently?
SELECT Governor FROM party GROUP BY Governor ORDER BY COUNT(*) DESC LIMIT 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 people that have been comptroller the most times and the corresponding number of times.
SELECT Comptroller , COUNT(*) FROM party GROUP BY Comptroller ORDER BY COUNT(*) DESC LIMIT 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`) )
Which people severed as comptroller most frequently? Give me the name of the person and the frequency count.
SELECT Comptroller , COUNT(*) FROM party GROUP BY Comptroller ORDER BY COUNT(*) DESC LIMIT 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`) )
What are the names of parties that do not have delegates in election?
SELECT Party FROM party WHERE Party_ID NOT IN (SELECT Party 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`) )
Which parties did not have any delegates in elections?
SELECT Party FROM party WHERE Party_ID NOT IN (SELECT Party 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 names of parties that have both delegates on "Appropriations" committee and
SELECT T2.Party FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T1.Committee = "Appropriations" INTERSECT SELECT T2.Party FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T1.Committee = "Economic Matters"
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`) )
Which parties have delegates in both the "Appropriations" committee and the "Economic Matters" committee?
SELECT T2.Party FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T1.Committee = "Appropriations" INTERSECT SELECT T2.Party FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T1.Committee = "Economic Matters"
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`) )
Which committees have delegates from both democratic party and liberal party?
SELECT T1.Committee FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T2.Party = "Democratic" INTERSECT SELECT T1.Committee FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T2.Party = "Liberal"
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`) )
Find the committees that have delegates both from from the democratic party and the liberal party.
SELECT T1.Committee FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T2.Party = "Democratic" INTERSECT SELECT T1.Committee FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T2.Party = "Liberal"
1
news_report
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ); CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ); CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") )
How many journalists are there?
SELECT count(*) FROM journalist
1
news_report
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ); CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ); CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") )
List the names of journalists in ascending order of years working.
SELECT Name FROM journalist ORDER BY Years_working ASC
1
news_report
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ); CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ); CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") )
What are the nationalities and ages of journalists?
SELECT Nationality , Age FROM journalist
1
news_report
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ); CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ); CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") )
Show the names of journalists from "England" or "Wales".
SELECT Name FROM journalist WHERE Nationality = "England" OR Nationality = "Wales"
1
news_report
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ); CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ); CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") )
What is the average number of years spent working as a journalist?
SELECT avg(Years_working) FROM journalist
1
news_report
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ); CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ); CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") )
What is the nationality of the journalist with the largest number of years working?
SELECT Nationality FROM journalist ORDER BY Years_working DESC LIMIT 1
1
news_report
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ); CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ); CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") )
Show the different nationalities and the number of journalists of each nationality.
SELECT Nationality , COUNT(*) FROM journalist GROUP BY Nationality
1
news_report
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ); CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ); CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") )
Show the most common nationality for journalists.
SELECT Nationality FROM journalist GROUP BY Nationality ORDER BY COUNT(*) DESC LIMIT 1
1
news_report
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ); CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ); CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") )
Show the nations that have both journalists with more than 10 years of working and journalists with less than 3 years of working.
SELECT Nationality FROM journalist WHERE Years_working > 10 INTERSECT SELECT Nationality FROM journalist WHERE Years_working < 3
1
news_report
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ); CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ); CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") )
Show the dates, places, and names of events in descending order of the attendance.
SELECT Date , Name , venue FROM event ORDER BY Event_Attendance DESC
1
news_report
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ); CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ); CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") )
Show the names of journalists and the dates of the events they reported.
SELECT T3.Name , T2.Date FROM news_report AS T1 JOIN event AS T2 ON T1.Event_ID = T2.Event_ID JOIN journalist AS T3 ON T1.journalist_ID = T3.journalist_ID
1
news_report
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ); CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ); CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") )
Show the names of journalists and the names of the events they reported in ascending order
SELECT T3.Name , T2.Name FROM news_report AS T1 JOIN event AS T2 ON T1.Event_ID = T2.Event_ID JOIN journalist AS T3 ON T1.journalist_ID = T3.journalist_ID ORDER BY T2.Event_Attendance ASC
1
news_report
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ); CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ); CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") )
Show the names of journalists and the number of events they reported.
SELECT T3.Name , COUNT(*) FROM news_report AS T1 JOIN event AS T2 ON T1.Event_ID = T2.Event_ID JOIN journalist AS T3 ON T1.journalist_ID = T3.journalist_ID GROUP BY T3.Name
1
news_report
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ); CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ); CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") )
Show the names of journalists that have reported more than one event.
SELECT T3.Name FROM news_report AS T1 JOIN event AS T2 ON T1.Event_ID = T2.Event_ID JOIN journalist AS T3 ON T1.journalist_ID = T3.journalist_ID GROUP BY T3.Name HAVING COUNT(*) > 1
1
news_report
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ); CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ); CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") )
List the names of journalists who have not reported any event.
SELECT Name FROM journalist WHERE journalist_ID NOT IN (SELECT journalist_ID FROM news_report)
1
news_report
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ); CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ); CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") )
what are the average and maximum attendances of all events?
SELECT avg(Event_Attendance) , max(Event_Attendance) FROM event
1
news_report
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ); CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ); CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") )
Find the average age and experience working length of journalists working on different role type.
SELECT avg(t1.age) , avg(Years_working) , t2.work_type FROM journalist AS t1 JOIN news_report AS t2 ON t1.journalist_id = t2.journalist_id GROUP BY t2.work_type
1
news_report
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ); CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ); CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") )
List the event venues and names that have the top 2 most number of people attended.
SELECT venue , name FROM event ORDER BY Event_Attendance DESC LIMIT 2
1
restaurant_1
Show me all the restaurants.
SELECT ResName FROM Restaurant;
1
restaurant_1
What is the address of the restaurant Subway?
SELECT Address FROM Restaurant WHERE ResName = "Subway";
1
restaurant_1
What is the rating of the restaurant Subway?
SELECT Rating FROM Restaurant WHERE ResName = "Subway";
1
restaurant_1
List all restaurant types.
SELECT ResTypeName FROM Restaurant_Type;
1
restaurant_1
What is the description of the restaurant type Sandwich?
SELECT ResTypeDescription FROM Restaurant_Type WHERE ResTypeName = "Sandwich";
1
restaurant_1
Which restaurants have highest rating? List the restaurant name and its rating.
SELECT ResName , Rating FROM Restaurant ORDER BY Rating DESC LIMIT 1;
1
restaurant_1
What is the age of student Linda Smith?
SELECT Age FROM Student WHERE Fname = "Linda" AND Lname = "Smith";
1
restaurant_1
What is the gender of the student Linda Smith?
SELECT Sex FROM Student WHERE Fname = "Linda" AND Lname = "Smith";
1
restaurant_1
List all students' first names and last names who majored in 600.
SELECT Fname , Lname FROM Student WHERE Major = 600;
1
restaurant_1
Which city does student Linda Smith live in?
SELECT city_code FROM Student WHERE Fname = "Linda" AND Lname = "Smith";
1
restaurant_1
Advisor 1121 has how many students?
SELECT count(*) FROM Student WHERE Advisor = 1121;
1
restaurant_1
Which Advisor has most of students? List advisor and the number of students.
SELECT Advisor , count(*) FROM Student GROUP BY Advisor ORDER BY count(Advisor) DESC LIMIT 1;
1
restaurant_1
Which major has least number of students? List the major and the number of students.
SELECT Major , count(*) FROM Student GROUP BY Major ORDER BY count(Major) ASC LIMIT 1;
1
restaurant_1
Which major has between 2 and 30 number of students? List major and the number of students.
SELECT Major , count(*) FROM Student GROUP BY Major HAVING count(Major) BETWEEN 2 AND 30;
1
restaurant_1
Which student's age is older than 18 and is majoring in 600? List each student's first and last name.
SELECT Fname , Lname FROM Student WHERE Age > 18 AND Major = 600;
1
restaurant_1
List all female students age is older than 18 who is not majoring in 600. List students' first name and last name.
SELECT Fname , Lname FROM Student WHERE Age > 18 AND Major != 600 AND Sex = 'F';
1
restaurant_1
How many restaurant is the Sandwich type restaurant?
SELECT count(*) FROM Restaurant JOIN Type_Of_Restaurant ON Restaurant.ResID = Type_Of_Restaurant.ResID JOIN Restaurant_Type ON Type_Of_Restaurant.ResTypeID = Restaurant_Type.ResTypeID GROUP BY Type_Of_Restaurant.ResTypeID HAVING Restaurant_Type.ResTypeName = 'Sandwich'
1
restaurant_1
How long does student Linda Smith spend on the restaurant in total?
SELECT sum(Spent) FROM Student JOIN Visits_Restaurant ON Student.StuID = Visits_Restaurant.StuID WHERE Student.Fname = "Linda" AND Student.Lname = "Smith";
1
restaurant_1
How many times has the student Linda Smith visited Subway?
SELECT count(*) FROM Student JOIN Visits_Restaurant ON Student.StuID = Visits_Restaurant.StuID JOIN Restaurant ON Visits_Restaurant.ResID = Restaurant.ResID WHERE Student.Fname = "Linda" AND Student.Lname = "Smith" AND Restaurant.ResName = "Subway";
1
restaurant_1
When did Linda Smith visit Subway?
SELECT TIME FROM Student JOIN Visits_Restaurant ON Student.StuID = Visits_Restaurant.StuID JOIN Restaurant ON Visits_Restaurant.ResID = Restaurant.ResID WHERE Student.Fname = "Linda" AND Student.Lname = "Smith" AND Restaurant.ResName = "Subway";
1
restaurant_1
At which restaurant did the students spend the least amount of time? List restaurant and the time students spent on in total.
SELECT Restaurant.ResName , sum(Visits_Restaurant.Spent) FROM Visits_Restaurant JOIN Restaurant ON Visits_Restaurant.ResID = Restaurant.ResID GROUP BY Restaurant.ResID ORDER BY sum(Visits_Restaurant.Spent) ASC LIMIT 1;
1
restaurant_1
Which student visited restaurant most often? List student's first name and last name.
SELECT Student.Fname , Student.Lname FROM Student JOIN Visits_Restaurant ON Student.StuID = Visits_Restaurant.StuID GROUP BY Student.StuID ORDER BY count(*) DESC LIMIT 1;
1
customer_deliveries
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ); CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ); CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ); CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ); CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ); CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ); CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) )
Find the ids of orders whose status is 'Success'.
SELECT actual_order_id FROM actual_orders WHERE order_status_code = 'Success'
1
customer_deliveries
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ); CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ); CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ); CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ); CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ); CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ); CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) )
Find the name and price of the product that has been ordered the greatest number of times.
SELECT t1.product_name , t1.product_price FROM products AS t1 JOIN regular_order_products AS t2 ON t1.product_id = t2.product_id GROUP BY t2.product_id ORDER BY count(*) DESC LIMIT 1
1
customer_deliveries
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ); CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ); CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ); CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ); CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ); CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ); CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) )
Find the number of customers in total.
SELECT count(*) FROM customers
1
customer_deliveries
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ); CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ); CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ); CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ); CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ); CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ); CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) )
How many different payment methods are there?
SELECT count(DISTINCT payment_method) FROM customers
1
customer_deliveries
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ); CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ); CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ); CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ); CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ); CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ); CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) )
Show the details of all trucks in the order of their license number.
SELECT truck_details FROM trucks ORDER BY truck_licence_number
1
customer_deliveries
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ); CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ); CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ); CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ); CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ); CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ); CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) )
Find the name of the most expensive product.
SELECT product_name FROM products ORDER BY product_price DESC LIMIT 1
1
customer_deliveries
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ); CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ); CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ); CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ); CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ); CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ); CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) )
Find the names of customers who are not living in the state of California.
SELECT customer_name FROM customers EXCEPT SELECT t1.customer_name FROM customers AS t1 JOIN customer_addresses AS t2 ON t1.customer_id = t2.customer_id JOIN addresses AS t3 ON t2.address_id = t3.address_id WHERE t3.state_province_county = 'California'
1
customer_deliveries
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ); CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ); CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ); CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ); CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ); CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ); CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) )
List the names and emails of customers who payed by Visa card.
SELECT customer_email , customer_name FROM customers WHERE payment_method = 'Visa'
1
customer_deliveries
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ); CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ); CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ); CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ); CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ); CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ); CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) )
Find the names and phone numbers of customers living in California state.
SELECT t1.customer_name , t1.customer_phone FROM customers AS t1 JOIN customer_addresses AS t2 ON t1.customer_id = t2.customer_id JOIN addresses AS t3 ON t2.address_id = t3.address_id WHERE t3.state_province_county = 'California'
1
customer_deliveries
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ); CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ); CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ); CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ); CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ); CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ); CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) )
Find the states which do not have any employee in their record.
SELECT state_province_county FROM addresses WHERE address_id NOT IN (SELECT employee_address_id FROM Employees)