db_id
stringclasses
127 values
query
stringlengths
20
523
question
stringlengths
16
224
schema
stringclasses
127 values
aircraft
SELECT avg(T3.Total_Passengers) FROM aircraft AS T1 JOIN airport_aircraft AS T2 ON T1.Aircraft_ID = T2.Aircraft_ID JOIN airport AS T3 ON T2.Airport_ID = T3.Airport_ID WHERE T1.Aircraft = "Robinson R-22"
What is the average total number of passengers for all airports that the aircraft "Robinson R-22" visits?
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT T2.Location , T1.Aircraft FROM aircraft AS T1 JOIN MATCH AS T2 ON T1.Aircraft_ID = T2.Winning_Aircraft
Please list the location and the winning aircraft name.
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT T2.Location , T1.Aircraft FROM aircraft AS T1 JOIN MATCH AS T2 ON T1.Aircraft_ID = T2.Winning_Aircraft
What is the location and name of the winning aircraft?
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT T1.Aircraft FROM aircraft AS T1 JOIN MATCH AS T2 ON T1.Aircraft_ID = T2.Winning_Aircraft GROUP BY T2.Winning_Aircraft ORDER BY COUNT(*) DESC LIMIT 1
List the name of the aircraft that has been named winning aircraft the most number of times.
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT T1.Aircraft FROM aircraft AS T1 JOIN MATCH AS T2 ON T1.Aircraft_ID = T2.Winning_Aircraft GROUP BY T2.Winning_Aircraft ORDER BY COUNT(*) DESC LIMIT 1
What is the name of the aircraft that has won an award the most?
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT T1.Aircraft , COUNT(*) FROM aircraft AS T1 JOIN MATCH AS T2 ON T1.Aircraft_ID = T2.Winning_Aircraft GROUP BY T2.Winning_Aircraft
List the names of aircrafts and the number of times it won matches.
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT T1.Aircraft , COUNT(*) FROM aircraft AS T1 JOIN MATCH AS T2 ON T1.Aircraft_ID = T2.Winning_Aircraft GROUP BY T2.Winning_Aircraft
For each aircraft that has won an award, what is its name and how many time has it won?
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT Name FROM pilot ORDER BY Age DESC
List names of all pilot in descending order of age.
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT Name FROM pilot ORDER BY Age DESC
What are the names of all pilots listed by descending age?
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT T1.Aircraft FROM aircraft AS T1 JOIN MATCH AS T2 ON T1.Aircraft_ID = T2.Winning_Aircraft GROUP BY T2.Winning_Aircraft HAVING COUNT(*) >= 2
List the names of aircrafts and that won matches at least twice.
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT T1.Aircraft FROM aircraft AS T1 JOIN MATCH AS T2 ON T1.Aircraft_ID = T2.Winning_Aircraft GROUP BY T2.Winning_Aircraft HAVING COUNT(*) >= 2
What are the names of all aircrafts that have won a match at least twice?
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT Aircraft FROM aircraft WHERE Aircraft_ID NOT IN (SELECT Winning_Aircraft FROM MATCH)
List the names of aircrafts and that did not win any match.
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT Aircraft FROM aircraft WHERE Aircraft_ID NOT IN (SELECT Winning_Aircraft FROM MATCH)
What are the names of all aicrafts that have never won any match?
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT T1.Aircraft FROM aircraft AS T1 JOIN airport_aircraft AS T2 ON T1.Aircraft_ID = T2.Aircraft_ID JOIN airport AS T3 ON T2.Airport_ID = T3.Airport_ID WHERE T3.Airport_Name = "London Heathrow" INTERSECT SELECT T1.Aircraft FROM aircraft AS T1 JOIN airport_aircraft AS T2 ON T1.Aircraft_ID = T2.Aircraft_ID JOIN airport AS T3 ON T2.Airport_ID = T3.Airport_ID WHERE T3.Airport_Name = "London Gatwick"
Show the names of aircrafts that are associated with both an airport named "London Heathrow" and an airport named "London Gatwick"
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT T1.Aircraft FROM aircraft AS T1 JOIN airport_aircraft AS T2 ON T1.Aircraft_ID = T2.Aircraft_ID JOIN airport AS T3 ON T2.Airport_ID = T3.Airport_ID WHERE T3.Airport_Name = "London Heathrow" INTERSECT SELECT T1.Aircraft FROM aircraft AS T1 JOIN airport_aircraft AS T2 ON T1.Aircraft_ID = T2.Aircraft_ID JOIN airport AS T3 ON T2.Airport_ID = T3.Airport_ID WHERE T3.Airport_Name = "London Gatwick"
What are the names of all aircrafts that are associated with both London Heathrow and Gatwick airports?
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT * FROM airport ORDER BY International_Passengers DESC LIMIT 1
Show all information on the airport that has the largest number of international passengers.
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT * FROM airport ORDER BY International_Passengers DESC LIMIT 1
What is all the information on the airport with the largest number of international passengers?
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT t1.name , t1.age FROM pilot AS t1 JOIN MATCH AS t2 ON t1.pilot_id = t2.winning_pilot WHERE t1.age < 30 GROUP BY t2.winning_pilot ORDER BY count(*) DESC LIMIT 1
find the name and age of the pilot who has won the most number of times among the pilots who are younger than 30.
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT t1.name , t1.age FROM pilot AS t1 JOIN MATCH AS t2 ON t1.pilot_id = t2.winning_pilot WHERE t1.age < 30 GROUP BY t2.winning_pilot ORDER BY count(*) DESC LIMIT 1
What is the name and age of the pilot younger than 30 who has won the most number of times?
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT t1.name , t1.age FROM pilot AS t1 JOIN MATCH AS t2 ON t1.pilot_id = t2.winning_pilot ORDER BY t1.age LIMIT 1
what is the name and age of the youngest winning pilot?
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT t1.name , t1.age FROM pilot AS t1 JOIN MATCH AS t2 ON t1.pilot_id = t2.winning_pilot ORDER BY t1.age LIMIT 1
How old is the youngest winning pilot and what is their name?
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT name FROM pilot WHERE pilot_id NOT IN (SELECT Winning_Pilot FROM MATCH WHERE country = 'Australia')
find the name of pilots who did not win the matches held in the country of Australia.
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
aircraft
SELECT name FROM pilot WHERE pilot_id NOT IN (SELECT Winning_Pilot FROM MATCH WHERE country = 'Australia')
What are the names of the pilots that have not won any matches in Australia?
PRAGMA foreign_keys = ON; CREATE TABLE `pilot` ( `Pilot_Id` int(11) NOT NULL, `Name` varchar(50) NOT NULL, `Age` int(11) NOT NULL, PRIMARY KEY (`Pilot_Id`) ); CREATE TABLE `aircraft` ( "Aircraft_ID" int(11) NOT NULL, "Aircraft" varchar(50) NOT NULL, "Description" varchar(50) NOT NULL, "Max_Gross_Weight" varchar(50) NOT NULL, "Total_disk_area" varchar(50) NOT NULL, "Max_disk_Loading" varchar(50) NOT NULL, PRIMARY KEY (`Aircraft_ID`) ); CREATE TABLE `match` ( "Round" real, "Location" text, "Country" text, "Date" text, "Fastest_Qualifying" text, "Winning_Pilot" text, "Winning_Aircraft" text, PRIMARY KEY ("Round"), FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`), FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`) ); CREATE TABLE `airport` ( "Airport_ID" int, "Airport_Name" text, "Total_Passengers" real, "%_Change_2007" text, "International_Passengers" real, "Domestic_Passengers" real, "Transit_Passengers" real, "Aircraft_Movements" real, "Freight_Metric_Tonnes" real, PRIMARY KEY ("Airport_ID") ); CREATE TABLE `airport_aircraft` ( "ID" int, "Airport_ID" int, "Aircraft_ID" int, PRIMARY KEY ("Airport_ID","Aircraft_ID"), FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`), FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`) ); INSERT INTO `pilot` (`Pilot_Id`, `Name`, `age`) VALUES (1, 'Prof. Zackery Collins', 23)INSERT INTO "aircraft" VALUES (1,"Robinson R-22","Light utility helicopter","1,370 lb (635 kg)","497 ft² (46.2 m²)INSERT INTO "match" VALUES ("1","Mina' Zayid , Abu Dhabi","United Arab Emirates","March 26–27","Hannes Arch",1,1); INSERT INTO "airport" VALUES (1,"London Heathrow","67054745","1.5%","61344438","5562516","147791","478693","1397054"); INSERT INTO "airport_aircraft" VALUES (1,6,5);
local_govt_and_lot
SELECT T1.property_id , count(*) FROM properties AS T1 JOIN residents AS T2 ON T1.property_id = T2.property_id GROUP BY T1.property_id
How many residents does each property have? List property id and resident count.
PRAGMA foreign_keys = ON; CREATE TABLE Customers ( customer_id INTEGER NOT NULL, customer_details VARCHAR(255), PRIMARY KEY (customer_id) ); CREATE TABLE Properties ( property_id INTEGER NOT NULL, property_type_code CHAR(15) NOT NULL, property_address VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (property_id) ); CREATE TABLE Residents ( resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, date_moved_out DATETIME NOT NULL, other_details VARCHAR(255), PRIMARY KEY (resident_id, property_id, date_moved_in), FOREIGN KEY (property_id) REFERENCES Properties (property_id) ); CREATE TABLE Organizations ( organization_id INTEGER NOT NULL, parent_organization_id INTEGER, organization_details VARCHAR(255), PRIMARY KEY (organization_id) ); CREATE TABLE Services ( service_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (service_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Residents_Services ( resident_id INTEGER NOT NULL, service_id INTEGER NOT NULL, date_moved_in DATETIME, property_id INTEGER, date_requested DATETIME, date_provided DATETIME, other_details VARCHAR(255), PRIMARY KEY (resident_id, service_id), FOREIGN KEY (service_id) REFERENCES Services (service_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Things ( thing_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, Type_of_Thing_Code CHAR(15) NOT NULL, service_type_code CHAR(10) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (thing_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Customer_Events ( Customer_Event_ID INTEGER NOT NULL, customer_id INTEGER, date_moved_in DATETIME, property_id INTEGER, resident_id INTEGER, thing_id INTEGER NOT NULL, PRIMARY KEY (Customer_Event_ID), FOREIGN KEY (thing_id) REFERENCES Things (thing_id), FOREIGN KEY (customer_id) REFERENCES Customers (customer_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Customer_Event_Notes ( Customer_Event_Note_ID INTEGER NOT NULL, Customer_Event_ID INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, PRIMARY KEY (Customer_Event_Note_ID), FOREIGN KEY (Customer_Event_ID) REFERENCES Customer_Events (Customer_Event_ID) ); CREATE TABLE Timed_Status_of_Things ( thing_id INTEGER NOT NULL, Date_and_Date DATETIME NOT NULL, Status_of_Thing_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Date, Status_of_Thing_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id) ); CREATE TABLE Timed_Locations_of_Things ( thing_id INTEGER NOT NULL, Date_and_Time DATETIME NOT NULL, Location_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Time, Location_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id)); INSERT INTO `Customers` (`customer_id`, `customer_details`) VALUES (4, 'Mr. Raul Prosacco')INSERT INTO `Properties` (`property_id`, `property_type_code`, `property_address`, `other_details`) VALUES (24, 'apartment', '85456 Annie Lodge Suite 449', 'USA')INSERT INTO `Residents` (`resident_id`, `property_id`, `date_moved_in`, `date_moved_out`, `other_details`) VALUES (6, 954, '2017-06-17 15:43:33', '2017-12-18 03:46:04', 'Anderson Batz')INSERT INTO `Organizations` (`organization_id`, `parent_organization_id`, `organization_details`) VALUES (7, 7, 'Reinger, Hudson and Nolan Group')INSERT INTO `Services` (`service_id`, `organization_id`, `service_type_code`, `service_details`) VALUES (10, 10, 'Cleanning', 'Satisfied')INSERT INTO `Residents_Services` (`resident_id`, `service_id`, `date_moved_in`, `property_id`, `date_requested`, `date_provided`, `other_details`) VALUES (6, 49, '2017-06-17 15:43:33', 954, '2016-07-25 01:32:23', '2018-02-26 00:27:11', 'Satisfied')INSERT INTO `Things` (`thing_id`, `organization_id`, `Type_of_Thing_Code`, `service_type_code`, `service_details`) VALUES (1, 8, 'Electronics', 'Check', 'Unsatisfied')INSERT INTO `Customer_Events` (`Customer_Event_ID`, `customer_id`, `date_moved_in`, `property_id`, `resident_id`, `thing_id`) VALUES (70, 19, '2015-03-27 12:00:00', 605, 10, 1)INSERT INTO `Customer_Event_Notes` (`Customer_Event_Note_ID`, `Customer_Event_ID`, `service_type_code`, `resident_id`, `property_id`, `date_moved_in`) VALUES (18, 70, 'Cleanning', 58, 107, '2016-08-04 01:06:05')INSERT INTO `Timed_Locations_of_Things` (`thing_id`, `Date_and_Time`, `Location_Code`) VALUES (2, '2016-10-12 12:03:07', '064 Charles Mou')INSERT INTO `Timed_Status_of_Things` (`thing_id`, `Date_and_Date`, `Status_of_Thing_Code`) VALUES (2, '2016-05-27 23:33:34', 'Open')
local_govt_and_lot
SELECT DISTINCT T1.service_type_code FROM services AS T1 JOIN organizations AS T2 ON T1.organization_id = T2.organization_id WHERE T2.organization_details = 'Denesik and Sons Party'
What is the distinct service types that are provided by the organization which has detail 'Denesik and Sons Party'?
PRAGMA foreign_keys = ON; CREATE TABLE Customers ( customer_id INTEGER NOT NULL, customer_details VARCHAR(255), PRIMARY KEY (customer_id) ); CREATE TABLE Properties ( property_id INTEGER NOT NULL, property_type_code CHAR(15) NOT NULL, property_address VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (property_id) ); CREATE TABLE Residents ( resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, date_moved_out DATETIME NOT NULL, other_details VARCHAR(255), PRIMARY KEY (resident_id, property_id, date_moved_in), FOREIGN KEY (property_id) REFERENCES Properties (property_id) ); CREATE TABLE Organizations ( organization_id INTEGER NOT NULL, parent_organization_id INTEGER, organization_details VARCHAR(255), PRIMARY KEY (organization_id) ); CREATE TABLE Services ( service_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (service_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Residents_Services ( resident_id INTEGER NOT NULL, service_id INTEGER NOT NULL, date_moved_in DATETIME, property_id INTEGER, date_requested DATETIME, date_provided DATETIME, other_details VARCHAR(255), PRIMARY KEY (resident_id, service_id), FOREIGN KEY (service_id) REFERENCES Services (service_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Things ( thing_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, Type_of_Thing_Code CHAR(15) NOT NULL, service_type_code CHAR(10) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (thing_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Customer_Events ( Customer_Event_ID INTEGER NOT NULL, customer_id INTEGER, date_moved_in DATETIME, property_id INTEGER, resident_id INTEGER, thing_id INTEGER NOT NULL, PRIMARY KEY (Customer_Event_ID), FOREIGN KEY (thing_id) REFERENCES Things (thing_id), FOREIGN KEY (customer_id) REFERENCES Customers (customer_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Customer_Event_Notes ( Customer_Event_Note_ID INTEGER NOT NULL, Customer_Event_ID INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, PRIMARY KEY (Customer_Event_Note_ID), FOREIGN KEY (Customer_Event_ID) REFERENCES Customer_Events (Customer_Event_ID) ); CREATE TABLE Timed_Status_of_Things ( thing_id INTEGER NOT NULL, Date_and_Date DATETIME NOT NULL, Status_of_Thing_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Date, Status_of_Thing_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id) ); CREATE TABLE Timed_Locations_of_Things ( thing_id INTEGER NOT NULL, Date_and_Time DATETIME NOT NULL, Location_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Time, Location_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id)); INSERT INTO `Customers` (`customer_id`, `customer_details`) VALUES (4, 'Mr. Raul Prosacco')INSERT INTO `Properties` (`property_id`, `property_type_code`, `property_address`, `other_details`) VALUES (24, 'apartment', '85456 Annie Lodge Suite 449', 'USA')INSERT INTO `Residents` (`resident_id`, `property_id`, `date_moved_in`, `date_moved_out`, `other_details`) VALUES (6, 954, '2017-06-17 15:43:33', '2017-12-18 03:46:04', 'Anderson Batz')INSERT INTO `Organizations` (`organization_id`, `parent_organization_id`, `organization_details`) VALUES (7, 7, 'Reinger, Hudson and Nolan Group')INSERT INTO `Services` (`service_id`, `organization_id`, `service_type_code`, `service_details`) VALUES (10, 10, 'Cleanning', 'Satisfied')INSERT INTO `Residents_Services` (`resident_id`, `service_id`, `date_moved_in`, `property_id`, `date_requested`, `date_provided`, `other_details`) VALUES (6, 49, '2017-06-17 15:43:33', 954, '2016-07-25 01:32:23', '2018-02-26 00:27:11', 'Satisfied')INSERT INTO `Things` (`thing_id`, `organization_id`, `Type_of_Thing_Code`, `service_type_code`, `service_details`) VALUES (1, 8, 'Electronics', 'Check', 'Unsatisfied')INSERT INTO `Customer_Events` (`Customer_Event_ID`, `customer_id`, `date_moved_in`, `property_id`, `resident_id`, `thing_id`) VALUES (70, 19, '2015-03-27 12:00:00', 605, 10, 1)INSERT INTO `Customer_Event_Notes` (`Customer_Event_Note_ID`, `Customer_Event_ID`, `service_type_code`, `resident_id`, `property_id`, `date_moved_in`) VALUES (18, 70, 'Cleanning', 58, 107, '2016-08-04 01:06:05')INSERT INTO `Timed_Locations_of_Things` (`thing_id`, `Date_and_Time`, `Location_Code`) VALUES (2, '2016-10-12 12:03:07', '064 Charles Mou')INSERT INTO `Timed_Status_of_Things` (`thing_id`, `Date_and_Date`, `Status_of_Thing_Code`) VALUES (2, '2016-05-27 23:33:34', 'Open')
local_govt_and_lot
SELECT T1.resident_id , T1.other_details , count(*) FROM Residents AS T1 JOIN Residents_Services AS T2 ON T1.resident_id = T2.resident_id GROUP BY T1.resident_id ORDER BY count(*) DESC
How many services has each resident requested? List the resident id, details, and the count in descending order of the count.
PRAGMA foreign_keys = ON; CREATE TABLE Customers ( customer_id INTEGER NOT NULL, customer_details VARCHAR(255), PRIMARY KEY (customer_id) ); CREATE TABLE Properties ( property_id INTEGER NOT NULL, property_type_code CHAR(15) NOT NULL, property_address VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (property_id) ); CREATE TABLE Residents ( resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, date_moved_out DATETIME NOT NULL, other_details VARCHAR(255), PRIMARY KEY (resident_id, property_id, date_moved_in), FOREIGN KEY (property_id) REFERENCES Properties (property_id) ); CREATE TABLE Organizations ( organization_id INTEGER NOT NULL, parent_organization_id INTEGER, organization_details VARCHAR(255), PRIMARY KEY (organization_id) ); CREATE TABLE Services ( service_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (service_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Residents_Services ( resident_id INTEGER NOT NULL, service_id INTEGER NOT NULL, date_moved_in DATETIME, property_id INTEGER, date_requested DATETIME, date_provided DATETIME, other_details VARCHAR(255), PRIMARY KEY (resident_id, service_id), FOREIGN KEY (service_id) REFERENCES Services (service_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Things ( thing_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, Type_of_Thing_Code CHAR(15) NOT NULL, service_type_code CHAR(10) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (thing_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Customer_Events ( Customer_Event_ID INTEGER NOT NULL, customer_id INTEGER, date_moved_in DATETIME, property_id INTEGER, resident_id INTEGER, thing_id INTEGER NOT NULL, PRIMARY KEY (Customer_Event_ID), FOREIGN KEY (thing_id) REFERENCES Things (thing_id), FOREIGN KEY (customer_id) REFERENCES Customers (customer_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Customer_Event_Notes ( Customer_Event_Note_ID INTEGER NOT NULL, Customer_Event_ID INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, PRIMARY KEY (Customer_Event_Note_ID), FOREIGN KEY (Customer_Event_ID) REFERENCES Customer_Events (Customer_Event_ID) ); CREATE TABLE Timed_Status_of_Things ( thing_id INTEGER NOT NULL, Date_and_Date DATETIME NOT NULL, Status_of_Thing_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Date, Status_of_Thing_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id) ); CREATE TABLE Timed_Locations_of_Things ( thing_id INTEGER NOT NULL, Date_and_Time DATETIME NOT NULL, Location_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Time, Location_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id)); INSERT INTO `Customers` (`customer_id`, `customer_details`) VALUES (4, 'Mr. Raul Prosacco')INSERT INTO `Properties` (`property_id`, `property_type_code`, `property_address`, `other_details`) VALUES (24, 'apartment', '85456 Annie Lodge Suite 449', 'USA')INSERT INTO `Residents` (`resident_id`, `property_id`, `date_moved_in`, `date_moved_out`, `other_details`) VALUES (6, 954, '2017-06-17 15:43:33', '2017-12-18 03:46:04', 'Anderson Batz')INSERT INTO `Organizations` (`organization_id`, `parent_organization_id`, `organization_details`) VALUES (7, 7, 'Reinger, Hudson and Nolan Group')INSERT INTO `Services` (`service_id`, `organization_id`, `service_type_code`, `service_details`) VALUES (10, 10, 'Cleanning', 'Satisfied')INSERT INTO `Residents_Services` (`resident_id`, `service_id`, `date_moved_in`, `property_id`, `date_requested`, `date_provided`, `other_details`) VALUES (6, 49, '2017-06-17 15:43:33', 954, '2016-07-25 01:32:23', '2018-02-26 00:27:11', 'Satisfied')INSERT INTO `Things` (`thing_id`, `organization_id`, `Type_of_Thing_Code`, `service_type_code`, `service_details`) VALUES (1, 8, 'Electronics', 'Check', 'Unsatisfied')INSERT INTO `Customer_Events` (`Customer_Event_ID`, `customer_id`, `date_moved_in`, `property_id`, `resident_id`, `thing_id`) VALUES (70, 19, '2015-03-27 12:00:00', 605, 10, 1)INSERT INTO `Customer_Event_Notes` (`Customer_Event_Note_ID`, `Customer_Event_ID`, `service_type_code`, `resident_id`, `property_id`, `date_moved_in`) VALUES (18, 70, 'Cleanning', 58, 107, '2016-08-04 01:06:05')INSERT INTO `Timed_Locations_of_Things` (`thing_id`, `Date_and_Time`, `Location_Code`) VALUES (2, '2016-10-12 12:03:07', '064 Charles Mou')INSERT INTO `Timed_Status_of_Things` (`thing_id`, `Date_and_Date`, `Status_of_Thing_Code`) VALUES (2, '2016-05-27 23:33:34', 'Open')
local_govt_and_lot
SELECT T1.service_id , T1.service_details , count(*) FROM Services AS T1 JOIN Residents_Services AS T2 ON T1.service_id = T2.service_id GROUP BY T1.service_id ORDER BY count(*) DESC LIMIT 1
What is the maximum number that a certain service is provided? List the service id, details and number.
PRAGMA foreign_keys = ON; CREATE TABLE Customers ( customer_id INTEGER NOT NULL, customer_details VARCHAR(255), PRIMARY KEY (customer_id) ); CREATE TABLE Properties ( property_id INTEGER NOT NULL, property_type_code CHAR(15) NOT NULL, property_address VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (property_id) ); CREATE TABLE Residents ( resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, date_moved_out DATETIME NOT NULL, other_details VARCHAR(255), PRIMARY KEY (resident_id, property_id, date_moved_in), FOREIGN KEY (property_id) REFERENCES Properties (property_id) ); CREATE TABLE Organizations ( organization_id INTEGER NOT NULL, parent_organization_id INTEGER, organization_details VARCHAR(255), PRIMARY KEY (organization_id) ); CREATE TABLE Services ( service_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (service_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Residents_Services ( resident_id INTEGER NOT NULL, service_id INTEGER NOT NULL, date_moved_in DATETIME, property_id INTEGER, date_requested DATETIME, date_provided DATETIME, other_details VARCHAR(255), PRIMARY KEY (resident_id, service_id), FOREIGN KEY (service_id) REFERENCES Services (service_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Things ( thing_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, Type_of_Thing_Code CHAR(15) NOT NULL, service_type_code CHAR(10) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (thing_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Customer_Events ( Customer_Event_ID INTEGER NOT NULL, customer_id INTEGER, date_moved_in DATETIME, property_id INTEGER, resident_id INTEGER, thing_id INTEGER NOT NULL, PRIMARY KEY (Customer_Event_ID), FOREIGN KEY (thing_id) REFERENCES Things (thing_id), FOREIGN KEY (customer_id) REFERENCES Customers (customer_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Customer_Event_Notes ( Customer_Event_Note_ID INTEGER NOT NULL, Customer_Event_ID INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, PRIMARY KEY (Customer_Event_Note_ID), FOREIGN KEY (Customer_Event_ID) REFERENCES Customer_Events (Customer_Event_ID) ); CREATE TABLE Timed_Status_of_Things ( thing_id INTEGER NOT NULL, Date_and_Date DATETIME NOT NULL, Status_of_Thing_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Date, Status_of_Thing_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id) ); CREATE TABLE Timed_Locations_of_Things ( thing_id INTEGER NOT NULL, Date_and_Time DATETIME NOT NULL, Location_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Time, Location_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id)); INSERT INTO `Customers` (`customer_id`, `customer_details`) VALUES (4, 'Mr. Raul Prosacco')INSERT INTO `Properties` (`property_id`, `property_type_code`, `property_address`, `other_details`) VALUES (24, 'apartment', '85456 Annie Lodge Suite 449', 'USA')INSERT INTO `Residents` (`resident_id`, `property_id`, `date_moved_in`, `date_moved_out`, `other_details`) VALUES (6, 954, '2017-06-17 15:43:33', '2017-12-18 03:46:04', 'Anderson Batz')INSERT INTO `Organizations` (`organization_id`, `parent_organization_id`, `organization_details`) VALUES (7, 7, 'Reinger, Hudson and Nolan Group')INSERT INTO `Services` (`service_id`, `organization_id`, `service_type_code`, `service_details`) VALUES (10, 10, 'Cleanning', 'Satisfied')INSERT INTO `Residents_Services` (`resident_id`, `service_id`, `date_moved_in`, `property_id`, `date_requested`, `date_provided`, `other_details`) VALUES (6, 49, '2017-06-17 15:43:33', 954, '2016-07-25 01:32:23', '2018-02-26 00:27:11', 'Satisfied')INSERT INTO `Things` (`thing_id`, `organization_id`, `Type_of_Thing_Code`, `service_type_code`, `service_details`) VALUES (1, 8, 'Electronics', 'Check', 'Unsatisfied')INSERT INTO `Customer_Events` (`Customer_Event_ID`, `customer_id`, `date_moved_in`, `property_id`, `resident_id`, `thing_id`) VALUES (70, 19, '2015-03-27 12:00:00', 605, 10, 1)INSERT INTO `Customer_Event_Notes` (`Customer_Event_Note_ID`, `Customer_Event_ID`, `service_type_code`, `resident_id`, `property_id`, `date_moved_in`) VALUES (18, 70, 'Cleanning', 58, 107, '2016-08-04 01:06:05')INSERT INTO `Timed_Locations_of_Things` (`thing_id`, `Date_and_Time`, `Location_Code`) VALUES (2, '2016-10-12 12:03:07', '064 Charles Mou')INSERT INTO `Timed_Status_of_Things` (`thing_id`, `Date_and_Date`, `Status_of_Thing_Code`) VALUES (2, '2016-05-27 23:33:34', 'Open')
local_govt_and_lot
SELECT T1.thing_id , T1.type_of_Thing_Code , T2.organization_details FROM Things AS T1 JOIN Organizations AS T2 ON T1.organization_id = T2.organization_id
List the id and type of each thing, and the details of the organization that owns it.
PRAGMA foreign_keys = ON; CREATE TABLE Customers ( customer_id INTEGER NOT NULL, customer_details VARCHAR(255), PRIMARY KEY (customer_id) ); CREATE TABLE Properties ( property_id INTEGER NOT NULL, property_type_code CHAR(15) NOT NULL, property_address VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (property_id) ); CREATE TABLE Residents ( resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, date_moved_out DATETIME NOT NULL, other_details VARCHAR(255), PRIMARY KEY (resident_id, property_id, date_moved_in), FOREIGN KEY (property_id) REFERENCES Properties (property_id) ); CREATE TABLE Organizations ( organization_id INTEGER NOT NULL, parent_organization_id INTEGER, organization_details VARCHAR(255), PRIMARY KEY (organization_id) ); CREATE TABLE Services ( service_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (service_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Residents_Services ( resident_id INTEGER NOT NULL, service_id INTEGER NOT NULL, date_moved_in DATETIME, property_id INTEGER, date_requested DATETIME, date_provided DATETIME, other_details VARCHAR(255), PRIMARY KEY (resident_id, service_id), FOREIGN KEY (service_id) REFERENCES Services (service_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Things ( thing_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, Type_of_Thing_Code CHAR(15) NOT NULL, service_type_code CHAR(10) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (thing_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Customer_Events ( Customer_Event_ID INTEGER NOT NULL, customer_id INTEGER, date_moved_in DATETIME, property_id INTEGER, resident_id INTEGER, thing_id INTEGER NOT NULL, PRIMARY KEY (Customer_Event_ID), FOREIGN KEY (thing_id) REFERENCES Things (thing_id), FOREIGN KEY (customer_id) REFERENCES Customers (customer_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Customer_Event_Notes ( Customer_Event_Note_ID INTEGER NOT NULL, Customer_Event_ID INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, PRIMARY KEY (Customer_Event_Note_ID), FOREIGN KEY (Customer_Event_ID) REFERENCES Customer_Events (Customer_Event_ID) ); CREATE TABLE Timed_Status_of_Things ( thing_id INTEGER NOT NULL, Date_and_Date DATETIME NOT NULL, Status_of_Thing_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Date, Status_of_Thing_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id) ); CREATE TABLE Timed_Locations_of_Things ( thing_id INTEGER NOT NULL, Date_and_Time DATETIME NOT NULL, Location_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Time, Location_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id)); INSERT INTO `Customers` (`customer_id`, `customer_details`) VALUES (4, 'Mr. Raul Prosacco')INSERT INTO `Properties` (`property_id`, `property_type_code`, `property_address`, `other_details`) VALUES (24, 'apartment', '85456 Annie Lodge Suite 449', 'USA')INSERT INTO `Residents` (`resident_id`, `property_id`, `date_moved_in`, `date_moved_out`, `other_details`) VALUES (6, 954, '2017-06-17 15:43:33', '2017-12-18 03:46:04', 'Anderson Batz')INSERT INTO `Organizations` (`organization_id`, `parent_organization_id`, `organization_details`) VALUES (7, 7, 'Reinger, Hudson and Nolan Group')INSERT INTO `Services` (`service_id`, `organization_id`, `service_type_code`, `service_details`) VALUES (10, 10, 'Cleanning', 'Satisfied')INSERT INTO `Residents_Services` (`resident_id`, `service_id`, `date_moved_in`, `property_id`, `date_requested`, `date_provided`, `other_details`) VALUES (6, 49, '2017-06-17 15:43:33', 954, '2016-07-25 01:32:23', '2018-02-26 00:27:11', 'Satisfied')INSERT INTO `Things` (`thing_id`, `organization_id`, `Type_of_Thing_Code`, `service_type_code`, `service_details`) VALUES (1, 8, 'Electronics', 'Check', 'Unsatisfied')INSERT INTO `Customer_Events` (`Customer_Event_ID`, `customer_id`, `date_moved_in`, `property_id`, `resident_id`, `thing_id`) VALUES (70, 19, '2015-03-27 12:00:00', 605, 10, 1)INSERT INTO `Customer_Event_Notes` (`Customer_Event_Note_ID`, `Customer_Event_ID`, `service_type_code`, `resident_id`, `property_id`, `date_moved_in`) VALUES (18, 70, 'Cleanning', 58, 107, '2016-08-04 01:06:05')INSERT INTO `Timed_Locations_of_Things` (`thing_id`, `Date_and_Time`, `Location_Code`) VALUES (2, '2016-10-12 12:03:07', '064 Charles Mou')INSERT INTO `Timed_Status_of_Things` (`thing_id`, `Date_and_Date`, `Status_of_Thing_Code`) VALUES (2, '2016-05-27 23:33:34', 'Open')
local_govt_and_lot
SELECT T1.customer_id , T1.customer_details FROM Customers AS T1 JOIN Customer_Events AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id HAVING count(*) >= 3
What are the id and details of the customers who have at least 3 events?
PRAGMA foreign_keys = ON; CREATE TABLE Customers ( customer_id INTEGER NOT NULL, customer_details VARCHAR(255), PRIMARY KEY (customer_id) ); CREATE TABLE Properties ( property_id INTEGER NOT NULL, property_type_code CHAR(15) NOT NULL, property_address VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (property_id) ); CREATE TABLE Residents ( resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, date_moved_out DATETIME NOT NULL, other_details VARCHAR(255), PRIMARY KEY (resident_id, property_id, date_moved_in), FOREIGN KEY (property_id) REFERENCES Properties (property_id) ); CREATE TABLE Organizations ( organization_id INTEGER NOT NULL, parent_organization_id INTEGER, organization_details VARCHAR(255), PRIMARY KEY (organization_id) ); CREATE TABLE Services ( service_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (service_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Residents_Services ( resident_id INTEGER NOT NULL, service_id INTEGER NOT NULL, date_moved_in DATETIME, property_id INTEGER, date_requested DATETIME, date_provided DATETIME, other_details VARCHAR(255), PRIMARY KEY (resident_id, service_id), FOREIGN KEY (service_id) REFERENCES Services (service_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Things ( thing_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, Type_of_Thing_Code CHAR(15) NOT NULL, service_type_code CHAR(10) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (thing_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Customer_Events ( Customer_Event_ID INTEGER NOT NULL, customer_id INTEGER, date_moved_in DATETIME, property_id INTEGER, resident_id INTEGER, thing_id INTEGER NOT NULL, PRIMARY KEY (Customer_Event_ID), FOREIGN KEY (thing_id) REFERENCES Things (thing_id), FOREIGN KEY (customer_id) REFERENCES Customers (customer_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Customer_Event_Notes ( Customer_Event_Note_ID INTEGER NOT NULL, Customer_Event_ID INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, PRIMARY KEY (Customer_Event_Note_ID), FOREIGN KEY (Customer_Event_ID) REFERENCES Customer_Events (Customer_Event_ID) ); CREATE TABLE Timed_Status_of_Things ( thing_id INTEGER NOT NULL, Date_and_Date DATETIME NOT NULL, Status_of_Thing_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Date, Status_of_Thing_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id) ); CREATE TABLE Timed_Locations_of_Things ( thing_id INTEGER NOT NULL, Date_and_Time DATETIME NOT NULL, Location_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Time, Location_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id)); INSERT INTO `Customers` (`customer_id`, `customer_details`) VALUES (4, 'Mr. Raul Prosacco')INSERT INTO `Properties` (`property_id`, `property_type_code`, `property_address`, `other_details`) VALUES (24, 'apartment', '85456 Annie Lodge Suite 449', 'USA')INSERT INTO `Residents` (`resident_id`, `property_id`, `date_moved_in`, `date_moved_out`, `other_details`) VALUES (6, 954, '2017-06-17 15:43:33', '2017-12-18 03:46:04', 'Anderson Batz')INSERT INTO `Organizations` (`organization_id`, `parent_organization_id`, `organization_details`) VALUES (7, 7, 'Reinger, Hudson and Nolan Group')INSERT INTO `Services` (`service_id`, `organization_id`, `service_type_code`, `service_details`) VALUES (10, 10, 'Cleanning', 'Satisfied')INSERT INTO `Residents_Services` (`resident_id`, `service_id`, `date_moved_in`, `property_id`, `date_requested`, `date_provided`, `other_details`) VALUES (6, 49, '2017-06-17 15:43:33', 954, '2016-07-25 01:32:23', '2018-02-26 00:27:11', 'Satisfied')INSERT INTO `Things` (`thing_id`, `organization_id`, `Type_of_Thing_Code`, `service_type_code`, `service_details`) VALUES (1, 8, 'Electronics', 'Check', 'Unsatisfied')INSERT INTO `Customer_Events` (`Customer_Event_ID`, `customer_id`, `date_moved_in`, `property_id`, `resident_id`, `thing_id`) VALUES (70, 19, '2015-03-27 12:00:00', 605, 10, 1)INSERT INTO `Customer_Event_Notes` (`Customer_Event_Note_ID`, `Customer_Event_ID`, `service_type_code`, `resident_id`, `property_id`, `date_moved_in`) VALUES (18, 70, 'Cleanning', 58, 107, '2016-08-04 01:06:05')INSERT INTO `Timed_Locations_of_Things` (`thing_id`, `Date_and_Time`, `Location_Code`) VALUES (2, '2016-10-12 12:03:07', '064 Charles Mou')INSERT INTO `Timed_Status_of_Things` (`thing_id`, `Date_and_Date`, `Status_of_Thing_Code`) VALUES (2, '2016-05-27 23:33:34', 'Open')
local_govt_and_lot
SELECT T2.date_moved_in , T1.customer_id , T1.customer_details FROM Customers AS T1 JOIN Customer_Events AS T2 ON T1.customer_id = T2.customer_id
What is each customer's move in date, and the corresponding customer id and details?
PRAGMA foreign_keys = ON; CREATE TABLE Customers ( customer_id INTEGER NOT NULL, customer_details VARCHAR(255), PRIMARY KEY (customer_id) ); CREATE TABLE Properties ( property_id INTEGER NOT NULL, property_type_code CHAR(15) NOT NULL, property_address VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (property_id) ); CREATE TABLE Residents ( resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, date_moved_out DATETIME NOT NULL, other_details VARCHAR(255), PRIMARY KEY (resident_id, property_id, date_moved_in), FOREIGN KEY (property_id) REFERENCES Properties (property_id) ); CREATE TABLE Organizations ( organization_id INTEGER NOT NULL, parent_organization_id INTEGER, organization_details VARCHAR(255), PRIMARY KEY (organization_id) ); CREATE TABLE Services ( service_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (service_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Residents_Services ( resident_id INTEGER NOT NULL, service_id INTEGER NOT NULL, date_moved_in DATETIME, property_id INTEGER, date_requested DATETIME, date_provided DATETIME, other_details VARCHAR(255), PRIMARY KEY (resident_id, service_id), FOREIGN KEY (service_id) REFERENCES Services (service_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Things ( thing_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, Type_of_Thing_Code CHAR(15) NOT NULL, service_type_code CHAR(10) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (thing_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Customer_Events ( Customer_Event_ID INTEGER NOT NULL, customer_id INTEGER, date_moved_in DATETIME, property_id INTEGER, resident_id INTEGER, thing_id INTEGER NOT NULL, PRIMARY KEY (Customer_Event_ID), FOREIGN KEY (thing_id) REFERENCES Things (thing_id), FOREIGN KEY (customer_id) REFERENCES Customers (customer_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Customer_Event_Notes ( Customer_Event_Note_ID INTEGER NOT NULL, Customer_Event_ID INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, PRIMARY KEY (Customer_Event_Note_ID), FOREIGN KEY (Customer_Event_ID) REFERENCES Customer_Events (Customer_Event_ID) ); CREATE TABLE Timed_Status_of_Things ( thing_id INTEGER NOT NULL, Date_and_Date DATETIME NOT NULL, Status_of_Thing_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Date, Status_of_Thing_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id) ); CREATE TABLE Timed_Locations_of_Things ( thing_id INTEGER NOT NULL, Date_and_Time DATETIME NOT NULL, Location_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Time, Location_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id)); INSERT INTO `Customers` (`customer_id`, `customer_details`) VALUES (4, 'Mr. Raul Prosacco')INSERT INTO `Properties` (`property_id`, `property_type_code`, `property_address`, `other_details`) VALUES (24, 'apartment', '85456 Annie Lodge Suite 449', 'USA')INSERT INTO `Residents` (`resident_id`, `property_id`, `date_moved_in`, `date_moved_out`, `other_details`) VALUES (6, 954, '2017-06-17 15:43:33', '2017-12-18 03:46:04', 'Anderson Batz')INSERT INTO `Organizations` (`organization_id`, `parent_organization_id`, `organization_details`) VALUES (7, 7, 'Reinger, Hudson and Nolan Group')INSERT INTO `Services` (`service_id`, `organization_id`, `service_type_code`, `service_details`) VALUES (10, 10, 'Cleanning', 'Satisfied')INSERT INTO `Residents_Services` (`resident_id`, `service_id`, `date_moved_in`, `property_id`, `date_requested`, `date_provided`, `other_details`) VALUES (6, 49, '2017-06-17 15:43:33', 954, '2016-07-25 01:32:23', '2018-02-26 00:27:11', 'Satisfied')INSERT INTO `Things` (`thing_id`, `organization_id`, `Type_of_Thing_Code`, `service_type_code`, `service_details`) VALUES (1, 8, 'Electronics', 'Check', 'Unsatisfied')INSERT INTO `Customer_Events` (`Customer_Event_ID`, `customer_id`, `date_moved_in`, `property_id`, `resident_id`, `thing_id`) VALUES (70, 19, '2015-03-27 12:00:00', 605, 10, 1)INSERT INTO `Customer_Event_Notes` (`Customer_Event_Note_ID`, `Customer_Event_ID`, `service_type_code`, `resident_id`, `property_id`, `date_moved_in`) VALUES (18, 70, 'Cleanning', 58, 107, '2016-08-04 01:06:05')INSERT INTO `Timed_Locations_of_Things` (`thing_id`, `Date_and_Time`, `Location_Code`) VALUES (2, '2016-10-12 12:03:07', '064 Charles Mou')INSERT INTO `Timed_Status_of_Things` (`thing_id`, `Date_and_Date`, `Status_of_Thing_Code`) VALUES (2, '2016-05-27 23:33:34', 'Open')
local_govt_and_lot
SELECT T1.Customer_Event_ID , T1.property_id FROM Customer_Events AS T1 JOIN Customer_Event_Notes AS T2 ON T1.Customer_Event_ID = T2.Customer_Event_ID GROUP BY T1.customer_event_id HAVING count(*) BETWEEN 1 AND 3
Which events have the number of notes between one and three? List the event id and the property id.
PRAGMA foreign_keys = ON; CREATE TABLE Customers ( customer_id INTEGER NOT NULL, customer_details VARCHAR(255), PRIMARY KEY (customer_id) ); CREATE TABLE Properties ( property_id INTEGER NOT NULL, property_type_code CHAR(15) NOT NULL, property_address VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (property_id) ); CREATE TABLE Residents ( resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, date_moved_out DATETIME NOT NULL, other_details VARCHAR(255), PRIMARY KEY (resident_id, property_id, date_moved_in), FOREIGN KEY (property_id) REFERENCES Properties (property_id) ); CREATE TABLE Organizations ( organization_id INTEGER NOT NULL, parent_organization_id INTEGER, organization_details VARCHAR(255), PRIMARY KEY (organization_id) ); CREATE TABLE Services ( service_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (service_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Residents_Services ( resident_id INTEGER NOT NULL, service_id INTEGER NOT NULL, date_moved_in DATETIME, property_id INTEGER, date_requested DATETIME, date_provided DATETIME, other_details VARCHAR(255), PRIMARY KEY (resident_id, service_id), FOREIGN KEY (service_id) REFERENCES Services (service_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Things ( thing_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, Type_of_Thing_Code CHAR(15) NOT NULL, service_type_code CHAR(10) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (thing_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Customer_Events ( Customer_Event_ID INTEGER NOT NULL, customer_id INTEGER, date_moved_in DATETIME, property_id INTEGER, resident_id INTEGER, thing_id INTEGER NOT NULL, PRIMARY KEY (Customer_Event_ID), FOREIGN KEY (thing_id) REFERENCES Things (thing_id), FOREIGN KEY (customer_id) REFERENCES Customers (customer_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Customer_Event_Notes ( Customer_Event_Note_ID INTEGER NOT NULL, Customer_Event_ID INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, PRIMARY KEY (Customer_Event_Note_ID), FOREIGN KEY (Customer_Event_ID) REFERENCES Customer_Events (Customer_Event_ID) ); CREATE TABLE Timed_Status_of_Things ( thing_id INTEGER NOT NULL, Date_and_Date DATETIME NOT NULL, Status_of_Thing_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Date, Status_of_Thing_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id) ); CREATE TABLE Timed_Locations_of_Things ( thing_id INTEGER NOT NULL, Date_and_Time DATETIME NOT NULL, Location_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Time, Location_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id)); INSERT INTO `Customers` (`customer_id`, `customer_details`) VALUES (4, 'Mr. Raul Prosacco')INSERT INTO `Properties` (`property_id`, `property_type_code`, `property_address`, `other_details`) VALUES (24, 'apartment', '85456 Annie Lodge Suite 449', 'USA')INSERT INTO `Residents` (`resident_id`, `property_id`, `date_moved_in`, `date_moved_out`, `other_details`) VALUES (6, 954, '2017-06-17 15:43:33', '2017-12-18 03:46:04', 'Anderson Batz')INSERT INTO `Organizations` (`organization_id`, `parent_organization_id`, `organization_details`) VALUES (7, 7, 'Reinger, Hudson and Nolan Group')INSERT INTO `Services` (`service_id`, `organization_id`, `service_type_code`, `service_details`) VALUES (10, 10, 'Cleanning', 'Satisfied')INSERT INTO `Residents_Services` (`resident_id`, `service_id`, `date_moved_in`, `property_id`, `date_requested`, `date_provided`, `other_details`) VALUES (6, 49, '2017-06-17 15:43:33', 954, '2016-07-25 01:32:23', '2018-02-26 00:27:11', 'Satisfied')INSERT INTO `Things` (`thing_id`, `organization_id`, `Type_of_Thing_Code`, `service_type_code`, `service_details`) VALUES (1, 8, 'Electronics', 'Check', 'Unsatisfied')INSERT INTO `Customer_Events` (`Customer_Event_ID`, `customer_id`, `date_moved_in`, `property_id`, `resident_id`, `thing_id`) VALUES (70, 19, '2015-03-27 12:00:00', 605, 10, 1)INSERT INTO `Customer_Event_Notes` (`Customer_Event_Note_ID`, `Customer_Event_ID`, `service_type_code`, `resident_id`, `property_id`, `date_moved_in`) VALUES (18, 70, 'Cleanning', 58, 107, '2016-08-04 01:06:05')INSERT INTO `Timed_Locations_of_Things` (`thing_id`, `Date_and_Time`, `Location_Code`) VALUES (2, '2016-10-12 12:03:07', '064 Charles Mou')INSERT INTO `Timed_Status_of_Things` (`thing_id`, `Date_and_Date`, `Status_of_Thing_Code`) VALUES (2, '2016-05-27 23:33:34', 'Open')
local_govt_and_lot
SELECT DISTINCT T2.thing_id , T2.Type_of_Thing_Code FROM Timed_Status_of_Things AS T1 JOIN Things AS T2 ON T1.thing_id = T2.thing_id WHERE T1.Status_of_Thing_Code = 'Close' OR T1.Date_and_Date < '2017-06-19 02:59:21'
What are the distinct id and type of the thing that has the status 'Close' or has a status record before the date '2017-06-19 02:59:21'
PRAGMA foreign_keys = ON; CREATE TABLE Customers ( customer_id INTEGER NOT NULL, customer_details VARCHAR(255), PRIMARY KEY (customer_id) ); CREATE TABLE Properties ( property_id INTEGER NOT NULL, property_type_code CHAR(15) NOT NULL, property_address VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (property_id) ); CREATE TABLE Residents ( resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, date_moved_out DATETIME NOT NULL, other_details VARCHAR(255), PRIMARY KEY (resident_id, property_id, date_moved_in), FOREIGN KEY (property_id) REFERENCES Properties (property_id) ); CREATE TABLE Organizations ( organization_id INTEGER NOT NULL, parent_organization_id INTEGER, organization_details VARCHAR(255), PRIMARY KEY (organization_id) ); CREATE TABLE Services ( service_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (service_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Residents_Services ( resident_id INTEGER NOT NULL, service_id INTEGER NOT NULL, date_moved_in DATETIME, property_id INTEGER, date_requested DATETIME, date_provided DATETIME, other_details VARCHAR(255), PRIMARY KEY (resident_id, service_id), FOREIGN KEY (service_id) REFERENCES Services (service_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Things ( thing_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, Type_of_Thing_Code CHAR(15) NOT NULL, service_type_code CHAR(10) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (thing_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Customer_Events ( Customer_Event_ID INTEGER NOT NULL, customer_id INTEGER, date_moved_in DATETIME, property_id INTEGER, resident_id INTEGER, thing_id INTEGER NOT NULL, PRIMARY KEY (Customer_Event_ID), FOREIGN KEY (thing_id) REFERENCES Things (thing_id), FOREIGN KEY (customer_id) REFERENCES Customers (customer_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Customer_Event_Notes ( Customer_Event_Note_ID INTEGER NOT NULL, Customer_Event_ID INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, PRIMARY KEY (Customer_Event_Note_ID), FOREIGN KEY (Customer_Event_ID) REFERENCES Customer_Events (Customer_Event_ID) ); CREATE TABLE Timed_Status_of_Things ( thing_id INTEGER NOT NULL, Date_and_Date DATETIME NOT NULL, Status_of_Thing_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Date, Status_of_Thing_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id) ); CREATE TABLE Timed_Locations_of_Things ( thing_id INTEGER NOT NULL, Date_and_Time DATETIME NOT NULL, Location_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Time, Location_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id)); INSERT INTO `Customers` (`customer_id`, `customer_details`) VALUES (4, 'Mr. Raul Prosacco')INSERT INTO `Properties` (`property_id`, `property_type_code`, `property_address`, `other_details`) VALUES (24, 'apartment', '85456 Annie Lodge Suite 449', 'USA')INSERT INTO `Residents` (`resident_id`, `property_id`, `date_moved_in`, `date_moved_out`, `other_details`) VALUES (6, 954, '2017-06-17 15:43:33', '2017-12-18 03:46:04', 'Anderson Batz')INSERT INTO `Organizations` (`organization_id`, `parent_organization_id`, `organization_details`) VALUES (7, 7, 'Reinger, Hudson and Nolan Group')INSERT INTO `Services` (`service_id`, `organization_id`, `service_type_code`, `service_details`) VALUES (10, 10, 'Cleanning', 'Satisfied')INSERT INTO `Residents_Services` (`resident_id`, `service_id`, `date_moved_in`, `property_id`, `date_requested`, `date_provided`, `other_details`) VALUES (6, 49, '2017-06-17 15:43:33', 954, '2016-07-25 01:32:23', '2018-02-26 00:27:11', 'Satisfied')INSERT INTO `Things` (`thing_id`, `organization_id`, `Type_of_Thing_Code`, `service_type_code`, `service_details`) VALUES (1, 8, 'Electronics', 'Check', 'Unsatisfied')INSERT INTO `Customer_Events` (`Customer_Event_ID`, `customer_id`, `date_moved_in`, `property_id`, `resident_id`, `thing_id`) VALUES (70, 19, '2015-03-27 12:00:00', 605, 10, 1)INSERT INTO `Customer_Event_Notes` (`Customer_Event_Note_ID`, `Customer_Event_ID`, `service_type_code`, `resident_id`, `property_id`, `date_moved_in`) VALUES (18, 70, 'Cleanning', 58, 107, '2016-08-04 01:06:05')INSERT INTO `Timed_Locations_of_Things` (`thing_id`, `Date_and_Time`, `Location_Code`) VALUES (2, '2016-10-12 12:03:07', '064 Charles Mou')INSERT INTO `Timed_Status_of_Things` (`thing_id`, `Date_and_Date`, `Status_of_Thing_Code`) VALUES (2, '2016-05-27 23:33:34', 'Open')
local_govt_and_lot
SELECT count(DISTINCT T2.Location_Code) FROM Things AS T1 JOIN Timed_Locations_of_Things AS T2 ON T1.thing_id = T2.thing_id WHERE T1.service_details = 'Unsatisfied'
How many distinct locations have the things with service detail 'Unsatisfied' been located in?
PRAGMA foreign_keys = ON; CREATE TABLE Customers ( customer_id INTEGER NOT NULL, customer_details VARCHAR(255), PRIMARY KEY (customer_id) ); CREATE TABLE Properties ( property_id INTEGER NOT NULL, property_type_code CHAR(15) NOT NULL, property_address VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (property_id) ); CREATE TABLE Residents ( resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, date_moved_out DATETIME NOT NULL, other_details VARCHAR(255), PRIMARY KEY (resident_id, property_id, date_moved_in), FOREIGN KEY (property_id) REFERENCES Properties (property_id) ); CREATE TABLE Organizations ( organization_id INTEGER NOT NULL, parent_organization_id INTEGER, organization_details VARCHAR(255), PRIMARY KEY (organization_id) ); CREATE TABLE Services ( service_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (service_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Residents_Services ( resident_id INTEGER NOT NULL, service_id INTEGER NOT NULL, date_moved_in DATETIME, property_id INTEGER, date_requested DATETIME, date_provided DATETIME, other_details VARCHAR(255), PRIMARY KEY (resident_id, service_id), FOREIGN KEY (service_id) REFERENCES Services (service_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Things ( thing_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, Type_of_Thing_Code CHAR(15) NOT NULL, service_type_code CHAR(10) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (thing_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Customer_Events ( Customer_Event_ID INTEGER NOT NULL, customer_id INTEGER, date_moved_in DATETIME, property_id INTEGER, resident_id INTEGER, thing_id INTEGER NOT NULL, PRIMARY KEY (Customer_Event_ID), FOREIGN KEY (thing_id) REFERENCES Things (thing_id), FOREIGN KEY (customer_id) REFERENCES Customers (customer_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Customer_Event_Notes ( Customer_Event_Note_ID INTEGER NOT NULL, Customer_Event_ID INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, PRIMARY KEY (Customer_Event_Note_ID), FOREIGN KEY (Customer_Event_ID) REFERENCES Customer_Events (Customer_Event_ID) ); CREATE TABLE Timed_Status_of_Things ( thing_id INTEGER NOT NULL, Date_and_Date DATETIME NOT NULL, Status_of_Thing_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Date, Status_of_Thing_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id) ); CREATE TABLE Timed_Locations_of_Things ( thing_id INTEGER NOT NULL, Date_and_Time DATETIME NOT NULL, Location_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Time, Location_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id)); INSERT INTO `Customers` (`customer_id`, `customer_details`) VALUES (4, 'Mr. Raul Prosacco')INSERT INTO `Properties` (`property_id`, `property_type_code`, `property_address`, `other_details`) VALUES (24, 'apartment', '85456 Annie Lodge Suite 449', 'USA')INSERT INTO `Residents` (`resident_id`, `property_id`, `date_moved_in`, `date_moved_out`, `other_details`) VALUES (6, 954, '2017-06-17 15:43:33', '2017-12-18 03:46:04', 'Anderson Batz')INSERT INTO `Organizations` (`organization_id`, `parent_organization_id`, `organization_details`) VALUES (7, 7, 'Reinger, Hudson and Nolan Group')INSERT INTO `Services` (`service_id`, `organization_id`, `service_type_code`, `service_details`) VALUES (10, 10, 'Cleanning', 'Satisfied')INSERT INTO `Residents_Services` (`resident_id`, `service_id`, `date_moved_in`, `property_id`, `date_requested`, `date_provided`, `other_details`) VALUES (6, 49, '2017-06-17 15:43:33', 954, '2016-07-25 01:32:23', '2018-02-26 00:27:11', 'Satisfied')INSERT INTO `Things` (`thing_id`, `organization_id`, `Type_of_Thing_Code`, `service_type_code`, `service_details`) VALUES (1, 8, 'Electronics', 'Check', 'Unsatisfied')INSERT INTO `Customer_Events` (`Customer_Event_ID`, `customer_id`, `date_moved_in`, `property_id`, `resident_id`, `thing_id`) VALUES (70, 19, '2015-03-27 12:00:00', 605, 10, 1)INSERT INTO `Customer_Event_Notes` (`Customer_Event_Note_ID`, `Customer_Event_ID`, `service_type_code`, `resident_id`, `property_id`, `date_moved_in`) VALUES (18, 70, 'Cleanning', 58, 107, '2016-08-04 01:06:05')INSERT INTO `Timed_Locations_of_Things` (`thing_id`, `Date_and_Time`, `Location_Code`) VALUES (2, '2016-10-12 12:03:07', '064 Charles Mou')INSERT INTO `Timed_Status_of_Things` (`thing_id`, `Date_and_Date`, `Status_of_Thing_Code`) VALUES (2, '2016-05-27 23:33:34', 'Open')
local_govt_and_lot
SELECT count(DISTINCT Status_of_Thing_Code) FROM Timed_Status_of_Things
How many different status codes of things are there?
PRAGMA foreign_keys = ON; CREATE TABLE Customers ( customer_id INTEGER NOT NULL, customer_details VARCHAR(255), PRIMARY KEY (customer_id) ); CREATE TABLE Properties ( property_id INTEGER NOT NULL, property_type_code CHAR(15) NOT NULL, property_address VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (property_id) ); CREATE TABLE Residents ( resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, date_moved_out DATETIME NOT NULL, other_details VARCHAR(255), PRIMARY KEY (resident_id, property_id, date_moved_in), FOREIGN KEY (property_id) REFERENCES Properties (property_id) ); CREATE TABLE Organizations ( organization_id INTEGER NOT NULL, parent_organization_id INTEGER, organization_details VARCHAR(255), PRIMARY KEY (organization_id) ); CREATE TABLE Services ( service_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (service_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Residents_Services ( resident_id INTEGER NOT NULL, service_id INTEGER NOT NULL, date_moved_in DATETIME, property_id INTEGER, date_requested DATETIME, date_provided DATETIME, other_details VARCHAR(255), PRIMARY KEY (resident_id, service_id), FOREIGN KEY (service_id) REFERENCES Services (service_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Things ( thing_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, Type_of_Thing_Code CHAR(15) NOT NULL, service_type_code CHAR(10) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (thing_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Customer_Events ( Customer_Event_ID INTEGER NOT NULL, customer_id INTEGER, date_moved_in DATETIME, property_id INTEGER, resident_id INTEGER, thing_id INTEGER NOT NULL, PRIMARY KEY (Customer_Event_ID), FOREIGN KEY (thing_id) REFERENCES Things (thing_id), FOREIGN KEY (customer_id) REFERENCES Customers (customer_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Customer_Event_Notes ( Customer_Event_Note_ID INTEGER NOT NULL, Customer_Event_ID INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, PRIMARY KEY (Customer_Event_Note_ID), FOREIGN KEY (Customer_Event_ID) REFERENCES Customer_Events (Customer_Event_ID) ); CREATE TABLE Timed_Status_of_Things ( thing_id INTEGER NOT NULL, Date_and_Date DATETIME NOT NULL, Status_of_Thing_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Date, Status_of_Thing_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id) ); CREATE TABLE Timed_Locations_of_Things ( thing_id INTEGER NOT NULL, Date_and_Time DATETIME NOT NULL, Location_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Time, Location_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id)); INSERT INTO `Customers` (`customer_id`, `customer_details`) VALUES (4, 'Mr. Raul Prosacco')INSERT INTO `Properties` (`property_id`, `property_type_code`, `property_address`, `other_details`) VALUES (24, 'apartment', '85456 Annie Lodge Suite 449', 'USA')INSERT INTO `Residents` (`resident_id`, `property_id`, `date_moved_in`, `date_moved_out`, `other_details`) VALUES (6, 954, '2017-06-17 15:43:33', '2017-12-18 03:46:04', 'Anderson Batz')INSERT INTO `Organizations` (`organization_id`, `parent_organization_id`, `organization_details`) VALUES (7, 7, 'Reinger, Hudson and Nolan Group')INSERT INTO `Services` (`service_id`, `organization_id`, `service_type_code`, `service_details`) VALUES (10, 10, 'Cleanning', 'Satisfied')INSERT INTO `Residents_Services` (`resident_id`, `service_id`, `date_moved_in`, `property_id`, `date_requested`, `date_provided`, `other_details`) VALUES (6, 49, '2017-06-17 15:43:33', 954, '2016-07-25 01:32:23', '2018-02-26 00:27:11', 'Satisfied')INSERT INTO `Things` (`thing_id`, `organization_id`, `Type_of_Thing_Code`, `service_type_code`, `service_details`) VALUES (1, 8, 'Electronics', 'Check', 'Unsatisfied')INSERT INTO `Customer_Events` (`Customer_Event_ID`, `customer_id`, `date_moved_in`, `property_id`, `resident_id`, `thing_id`) VALUES (70, 19, '2015-03-27 12:00:00', 605, 10, 1)INSERT INTO `Customer_Event_Notes` (`Customer_Event_Note_ID`, `Customer_Event_ID`, `service_type_code`, `resident_id`, `property_id`, `date_moved_in`) VALUES (18, 70, 'Cleanning', 58, 107, '2016-08-04 01:06:05')INSERT INTO `Timed_Locations_of_Things` (`thing_id`, `Date_and_Time`, `Location_Code`) VALUES (2, '2016-10-12 12:03:07', '064 Charles Mou')INSERT INTO `Timed_Status_of_Things` (`thing_id`, `Date_and_Date`, `Status_of_Thing_Code`) VALUES (2, '2016-05-27 23:33:34', 'Open')
local_govt_and_lot
SELECT organization_id FROM organizations EXCEPT SELECT parent_organization_id FROM organizations
Which organizations are not a parent organization of others? List the organization id.
PRAGMA foreign_keys = ON; CREATE TABLE Customers ( customer_id INTEGER NOT NULL, customer_details VARCHAR(255), PRIMARY KEY (customer_id) ); CREATE TABLE Properties ( property_id INTEGER NOT NULL, property_type_code CHAR(15) NOT NULL, property_address VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (property_id) ); CREATE TABLE Residents ( resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, date_moved_out DATETIME NOT NULL, other_details VARCHAR(255), PRIMARY KEY (resident_id, property_id, date_moved_in), FOREIGN KEY (property_id) REFERENCES Properties (property_id) ); CREATE TABLE Organizations ( organization_id INTEGER NOT NULL, parent_organization_id INTEGER, organization_details VARCHAR(255), PRIMARY KEY (organization_id) ); CREATE TABLE Services ( service_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (service_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Residents_Services ( resident_id INTEGER NOT NULL, service_id INTEGER NOT NULL, date_moved_in DATETIME, property_id INTEGER, date_requested DATETIME, date_provided DATETIME, other_details VARCHAR(255), PRIMARY KEY (resident_id, service_id), FOREIGN KEY (service_id) REFERENCES Services (service_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Things ( thing_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, Type_of_Thing_Code CHAR(15) NOT NULL, service_type_code CHAR(10) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (thing_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Customer_Events ( Customer_Event_ID INTEGER NOT NULL, customer_id INTEGER, date_moved_in DATETIME, property_id INTEGER, resident_id INTEGER, thing_id INTEGER NOT NULL, PRIMARY KEY (Customer_Event_ID), FOREIGN KEY (thing_id) REFERENCES Things (thing_id), FOREIGN KEY (customer_id) REFERENCES Customers (customer_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Customer_Event_Notes ( Customer_Event_Note_ID INTEGER NOT NULL, Customer_Event_ID INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, PRIMARY KEY (Customer_Event_Note_ID), FOREIGN KEY (Customer_Event_ID) REFERENCES Customer_Events (Customer_Event_ID) ); CREATE TABLE Timed_Status_of_Things ( thing_id INTEGER NOT NULL, Date_and_Date DATETIME NOT NULL, Status_of_Thing_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Date, Status_of_Thing_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id) ); CREATE TABLE Timed_Locations_of_Things ( thing_id INTEGER NOT NULL, Date_and_Time DATETIME NOT NULL, Location_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Time, Location_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id)); INSERT INTO `Customers` (`customer_id`, `customer_details`) VALUES (4, 'Mr. Raul Prosacco')INSERT INTO `Properties` (`property_id`, `property_type_code`, `property_address`, `other_details`) VALUES (24, 'apartment', '85456 Annie Lodge Suite 449', 'USA')INSERT INTO `Residents` (`resident_id`, `property_id`, `date_moved_in`, `date_moved_out`, `other_details`) VALUES (6, 954, '2017-06-17 15:43:33', '2017-12-18 03:46:04', 'Anderson Batz')INSERT INTO `Organizations` (`organization_id`, `parent_organization_id`, `organization_details`) VALUES (7, 7, 'Reinger, Hudson and Nolan Group')INSERT INTO `Services` (`service_id`, `organization_id`, `service_type_code`, `service_details`) VALUES (10, 10, 'Cleanning', 'Satisfied')INSERT INTO `Residents_Services` (`resident_id`, `service_id`, `date_moved_in`, `property_id`, `date_requested`, `date_provided`, `other_details`) VALUES (6, 49, '2017-06-17 15:43:33', 954, '2016-07-25 01:32:23', '2018-02-26 00:27:11', 'Satisfied')INSERT INTO `Things` (`thing_id`, `organization_id`, `Type_of_Thing_Code`, `service_type_code`, `service_details`) VALUES (1, 8, 'Electronics', 'Check', 'Unsatisfied')INSERT INTO `Customer_Events` (`Customer_Event_ID`, `customer_id`, `date_moved_in`, `property_id`, `resident_id`, `thing_id`) VALUES (70, 19, '2015-03-27 12:00:00', 605, 10, 1)INSERT INTO `Customer_Event_Notes` (`Customer_Event_Note_ID`, `Customer_Event_ID`, `service_type_code`, `resident_id`, `property_id`, `date_moved_in`) VALUES (18, 70, 'Cleanning', 58, 107, '2016-08-04 01:06:05')INSERT INTO `Timed_Locations_of_Things` (`thing_id`, `Date_and_Time`, `Location_Code`) VALUES (2, '2016-10-12 12:03:07', '064 Charles Mou')INSERT INTO `Timed_Status_of_Things` (`thing_id`, `Date_and_Date`, `Status_of_Thing_Code`) VALUES (2, '2016-05-27 23:33:34', 'Open')
local_govt_and_lot
SELECT max(date_moved_in) FROM Residents
When is the last day any resident moved in?
PRAGMA foreign_keys = ON; CREATE TABLE Customers ( customer_id INTEGER NOT NULL, customer_details VARCHAR(255), PRIMARY KEY (customer_id) ); CREATE TABLE Properties ( property_id INTEGER NOT NULL, property_type_code CHAR(15) NOT NULL, property_address VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (property_id) ); CREATE TABLE Residents ( resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, date_moved_out DATETIME NOT NULL, other_details VARCHAR(255), PRIMARY KEY (resident_id, property_id, date_moved_in), FOREIGN KEY (property_id) REFERENCES Properties (property_id) ); CREATE TABLE Organizations ( organization_id INTEGER NOT NULL, parent_organization_id INTEGER, organization_details VARCHAR(255), PRIMARY KEY (organization_id) ); CREATE TABLE Services ( service_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (service_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Residents_Services ( resident_id INTEGER NOT NULL, service_id INTEGER NOT NULL, date_moved_in DATETIME, property_id INTEGER, date_requested DATETIME, date_provided DATETIME, other_details VARCHAR(255), PRIMARY KEY (resident_id, service_id), FOREIGN KEY (service_id) REFERENCES Services (service_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Things ( thing_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, Type_of_Thing_Code CHAR(15) NOT NULL, service_type_code CHAR(10) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (thing_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Customer_Events ( Customer_Event_ID INTEGER NOT NULL, customer_id INTEGER, date_moved_in DATETIME, property_id INTEGER, resident_id INTEGER, thing_id INTEGER NOT NULL, PRIMARY KEY (Customer_Event_ID), FOREIGN KEY (thing_id) REFERENCES Things (thing_id), FOREIGN KEY (customer_id) REFERENCES Customers (customer_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Customer_Event_Notes ( Customer_Event_Note_ID INTEGER NOT NULL, Customer_Event_ID INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, PRIMARY KEY (Customer_Event_Note_ID), FOREIGN KEY (Customer_Event_ID) REFERENCES Customer_Events (Customer_Event_ID) ); CREATE TABLE Timed_Status_of_Things ( thing_id INTEGER NOT NULL, Date_and_Date DATETIME NOT NULL, Status_of_Thing_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Date, Status_of_Thing_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id) ); CREATE TABLE Timed_Locations_of_Things ( thing_id INTEGER NOT NULL, Date_and_Time DATETIME NOT NULL, Location_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Time, Location_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id)); INSERT INTO `Customers` (`customer_id`, `customer_details`) VALUES (4, 'Mr. Raul Prosacco')INSERT INTO `Properties` (`property_id`, `property_type_code`, `property_address`, `other_details`) VALUES (24, 'apartment', '85456 Annie Lodge Suite 449', 'USA')INSERT INTO `Residents` (`resident_id`, `property_id`, `date_moved_in`, `date_moved_out`, `other_details`) VALUES (6, 954, '2017-06-17 15:43:33', '2017-12-18 03:46:04', 'Anderson Batz')INSERT INTO `Organizations` (`organization_id`, `parent_organization_id`, `organization_details`) VALUES (7, 7, 'Reinger, Hudson and Nolan Group')INSERT INTO `Services` (`service_id`, `organization_id`, `service_type_code`, `service_details`) VALUES (10, 10, 'Cleanning', 'Satisfied')INSERT INTO `Residents_Services` (`resident_id`, `service_id`, `date_moved_in`, `property_id`, `date_requested`, `date_provided`, `other_details`) VALUES (6, 49, '2017-06-17 15:43:33', 954, '2016-07-25 01:32:23', '2018-02-26 00:27:11', 'Satisfied')INSERT INTO `Things` (`thing_id`, `organization_id`, `Type_of_Thing_Code`, `service_type_code`, `service_details`) VALUES (1, 8, 'Electronics', 'Check', 'Unsatisfied')INSERT INTO `Customer_Events` (`Customer_Event_ID`, `customer_id`, `date_moved_in`, `property_id`, `resident_id`, `thing_id`) VALUES (70, 19, '2015-03-27 12:00:00', 605, 10, 1)INSERT INTO `Customer_Event_Notes` (`Customer_Event_Note_ID`, `Customer_Event_ID`, `service_type_code`, `resident_id`, `property_id`, `date_moved_in`) VALUES (18, 70, 'Cleanning', 58, 107, '2016-08-04 01:06:05')INSERT INTO `Timed_Locations_of_Things` (`thing_id`, `Date_and_Time`, `Location_Code`) VALUES (2, '2016-10-12 12:03:07', '064 Charles Mou')INSERT INTO `Timed_Status_of_Things` (`thing_id`, `Date_and_Date`, `Status_of_Thing_Code`) VALUES (2, '2016-05-27 23:33:34', 'Open')
local_govt_and_lot
SELECT other_details FROM Residents WHERE other_details LIKE '%Miss%'
What are the resident details containing the substring 'Miss'?
PRAGMA foreign_keys = ON; CREATE TABLE Customers ( customer_id INTEGER NOT NULL, customer_details VARCHAR(255), PRIMARY KEY (customer_id) ); CREATE TABLE Properties ( property_id INTEGER NOT NULL, property_type_code CHAR(15) NOT NULL, property_address VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (property_id) ); CREATE TABLE Residents ( resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, date_moved_out DATETIME NOT NULL, other_details VARCHAR(255), PRIMARY KEY (resident_id, property_id, date_moved_in), FOREIGN KEY (property_id) REFERENCES Properties (property_id) ); CREATE TABLE Organizations ( organization_id INTEGER NOT NULL, parent_organization_id INTEGER, organization_details VARCHAR(255), PRIMARY KEY (organization_id) ); CREATE TABLE Services ( service_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (service_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Residents_Services ( resident_id INTEGER NOT NULL, service_id INTEGER NOT NULL, date_moved_in DATETIME, property_id INTEGER, date_requested DATETIME, date_provided DATETIME, other_details VARCHAR(255), PRIMARY KEY (resident_id, service_id), FOREIGN KEY (service_id) REFERENCES Services (service_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Things ( thing_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, Type_of_Thing_Code CHAR(15) NOT NULL, service_type_code CHAR(10) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (thing_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Customer_Events ( Customer_Event_ID INTEGER NOT NULL, customer_id INTEGER, date_moved_in DATETIME, property_id INTEGER, resident_id INTEGER, thing_id INTEGER NOT NULL, PRIMARY KEY (Customer_Event_ID), FOREIGN KEY (thing_id) REFERENCES Things (thing_id), FOREIGN KEY (customer_id) REFERENCES Customers (customer_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Customer_Event_Notes ( Customer_Event_Note_ID INTEGER NOT NULL, Customer_Event_ID INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, PRIMARY KEY (Customer_Event_Note_ID), FOREIGN KEY (Customer_Event_ID) REFERENCES Customer_Events (Customer_Event_ID) ); CREATE TABLE Timed_Status_of_Things ( thing_id INTEGER NOT NULL, Date_and_Date DATETIME NOT NULL, Status_of_Thing_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Date, Status_of_Thing_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id) ); CREATE TABLE Timed_Locations_of_Things ( thing_id INTEGER NOT NULL, Date_and_Time DATETIME NOT NULL, Location_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Time, Location_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id)); INSERT INTO `Customers` (`customer_id`, `customer_details`) VALUES (4, 'Mr. Raul Prosacco')INSERT INTO `Properties` (`property_id`, `property_type_code`, `property_address`, `other_details`) VALUES (24, 'apartment', '85456 Annie Lodge Suite 449', 'USA')INSERT INTO `Residents` (`resident_id`, `property_id`, `date_moved_in`, `date_moved_out`, `other_details`) VALUES (6, 954, '2017-06-17 15:43:33', '2017-12-18 03:46:04', 'Anderson Batz')INSERT INTO `Organizations` (`organization_id`, `parent_organization_id`, `organization_details`) VALUES (7, 7, 'Reinger, Hudson and Nolan Group')INSERT INTO `Services` (`service_id`, `organization_id`, `service_type_code`, `service_details`) VALUES (10, 10, 'Cleanning', 'Satisfied')INSERT INTO `Residents_Services` (`resident_id`, `service_id`, `date_moved_in`, `property_id`, `date_requested`, `date_provided`, `other_details`) VALUES (6, 49, '2017-06-17 15:43:33', 954, '2016-07-25 01:32:23', '2018-02-26 00:27:11', 'Satisfied')INSERT INTO `Things` (`thing_id`, `organization_id`, `Type_of_Thing_Code`, `service_type_code`, `service_details`) VALUES (1, 8, 'Electronics', 'Check', 'Unsatisfied')INSERT INTO `Customer_Events` (`Customer_Event_ID`, `customer_id`, `date_moved_in`, `property_id`, `resident_id`, `thing_id`) VALUES (70, 19, '2015-03-27 12:00:00', 605, 10, 1)INSERT INTO `Customer_Event_Notes` (`Customer_Event_Note_ID`, `Customer_Event_ID`, `service_type_code`, `resident_id`, `property_id`, `date_moved_in`) VALUES (18, 70, 'Cleanning', 58, 107, '2016-08-04 01:06:05')INSERT INTO `Timed_Locations_of_Things` (`thing_id`, `Date_and_Time`, `Location_Code`) VALUES (2, '2016-10-12 12:03:07', '064 Charles Mou')INSERT INTO `Timed_Status_of_Things` (`thing_id`, `Date_and_Date`, `Status_of_Thing_Code`) VALUES (2, '2016-05-27 23:33:34', 'Open')
local_govt_and_lot
SELECT customer_event_id , date_moved_in , property_id FROM customer_events
List the customer event id and the corresponding move in date and property id.
PRAGMA foreign_keys = ON; CREATE TABLE Customers ( customer_id INTEGER NOT NULL, customer_details VARCHAR(255), PRIMARY KEY (customer_id) ); CREATE TABLE Properties ( property_id INTEGER NOT NULL, property_type_code CHAR(15) NOT NULL, property_address VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (property_id) ); CREATE TABLE Residents ( resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, date_moved_out DATETIME NOT NULL, other_details VARCHAR(255), PRIMARY KEY (resident_id, property_id, date_moved_in), FOREIGN KEY (property_id) REFERENCES Properties (property_id) ); CREATE TABLE Organizations ( organization_id INTEGER NOT NULL, parent_organization_id INTEGER, organization_details VARCHAR(255), PRIMARY KEY (organization_id) ); CREATE TABLE Services ( service_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (service_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Residents_Services ( resident_id INTEGER NOT NULL, service_id INTEGER NOT NULL, date_moved_in DATETIME, property_id INTEGER, date_requested DATETIME, date_provided DATETIME, other_details VARCHAR(255), PRIMARY KEY (resident_id, service_id), FOREIGN KEY (service_id) REFERENCES Services (service_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Things ( thing_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, Type_of_Thing_Code CHAR(15) NOT NULL, service_type_code CHAR(10) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (thing_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Customer_Events ( Customer_Event_ID INTEGER NOT NULL, customer_id INTEGER, date_moved_in DATETIME, property_id INTEGER, resident_id INTEGER, thing_id INTEGER NOT NULL, PRIMARY KEY (Customer_Event_ID), FOREIGN KEY (thing_id) REFERENCES Things (thing_id), FOREIGN KEY (customer_id) REFERENCES Customers (customer_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Customer_Event_Notes ( Customer_Event_Note_ID INTEGER NOT NULL, Customer_Event_ID INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, PRIMARY KEY (Customer_Event_Note_ID), FOREIGN KEY (Customer_Event_ID) REFERENCES Customer_Events (Customer_Event_ID) ); CREATE TABLE Timed_Status_of_Things ( thing_id INTEGER NOT NULL, Date_and_Date DATETIME NOT NULL, Status_of_Thing_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Date, Status_of_Thing_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id) ); CREATE TABLE Timed_Locations_of_Things ( thing_id INTEGER NOT NULL, Date_and_Time DATETIME NOT NULL, Location_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Time, Location_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id)); INSERT INTO `Customers` (`customer_id`, `customer_details`) VALUES (4, 'Mr. Raul Prosacco')INSERT INTO `Properties` (`property_id`, `property_type_code`, `property_address`, `other_details`) VALUES (24, 'apartment', '85456 Annie Lodge Suite 449', 'USA')INSERT INTO `Residents` (`resident_id`, `property_id`, `date_moved_in`, `date_moved_out`, `other_details`) VALUES (6, 954, '2017-06-17 15:43:33', '2017-12-18 03:46:04', 'Anderson Batz')INSERT INTO `Organizations` (`organization_id`, `parent_organization_id`, `organization_details`) VALUES (7, 7, 'Reinger, Hudson and Nolan Group')INSERT INTO `Services` (`service_id`, `organization_id`, `service_type_code`, `service_details`) VALUES (10, 10, 'Cleanning', 'Satisfied')INSERT INTO `Residents_Services` (`resident_id`, `service_id`, `date_moved_in`, `property_id`, `date_requested`, `date_provided`, `other_details`) VALUES (6, 49, '2017-06-17 15:43:33', 954, '2016-07-25 01:32:23', '2018-02-26 00:27:11', 'Satisfied')INSERT INTO `Things` (`thing_id`, `organization_id`, `Type_of_Thing_Code`, `service_type_code`, `service_details`) VALUES (1, 8, 'Electronics', 'Check', 'Unsatisfied')INSERT INTO `Customer_Events` (`Customer_Event_ID`, `customer_id`, `date_moved_in`, `property_id`, `resident_id`, `thing_id`) VALUES (70, 19, '2015-03-27 12:00:00', 605, 10, 1)INSERT INTO `Customer_Event_Notes` (`Customer_Event_Note_ID`, `Customer_Event_ID`, `service_type_code`, `resident_id`, `property_id`, `date_moved_in`) VALUES (18, 70, 'Cleanning', 58, 107, '2016-08-04 01:06:05')INSERT INTO `Timed_Locations_of_Things` (`thing_id`, `Date_and_Time`, `Location_Code`) VALUES (2, '2016-10-12 12:03:07', '064 Charles Mou')INSERT INTO `Timed_Status_of_Things` (`thing_id`, `Date_and_Date`, `Status_of_Thing_Code`) VALUES (2, '2016-05-27 23:33:34', 'Open')
local_govt_and_lot
SELECT count(*) FROM customers WHERE customer_id NOT IN ( SELECT customer_id FROM customer_events )
How many customers did not have any event?
PRAGMA foreign_keys = ON; CREATE TABLE Customers ( customer_id INTEGER NOT NULL, customer_details VARCHAR(255), PRIMARY KEY (customer_id) ); CREATE TABLE Properties ( property_id INTEGER NOT NULL, property_type_code CHAR(15) NOT NULL, property_address VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (property_id) ); CREATE TABLE Residents ( resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, date_moved_out DATETIME NOT NULL, other_details VARCHAR(255), PRIMARY KEY (resident_id, property_id, date_moved_in), FOREIGN KEY (property_id) REFERENCES Properties (property_id) ); CREATE TABLE Organizations ( organization_id INTEGER NOT NULL, parent_organization_id INTEGER, organization_details VARCHAR(255), PRIMARY KEY (organization_id) ); CREATE TABLE Services ( service_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (service_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Residents_Services ( resident_id INTEGER NOT NULL, service_id INTEGER NOT NULL, date_moved_in DATETIME, property_id INTEGER, date_requested DATETIME, date_provided DATETIME, other_details VARCHAR(255), PRIMARY KEY (resident_id, service_id), FOREIGN KEY (service_id) REFERENCES Services (service_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Things ( thing_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, Type_of_Thing_Code CHAR(15) NOT NULL, service_type_code CHAR(10) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (thing_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Customer_Events ( Customer_Event_ID INTEGER NOT NULL, customer_id INTEGER, date_moved_in DATETIME, property_id INTEGER, resident_id INTEGER, thing_id INTEGER NOT NULL, PRIMARY KEY (Customer_Event_ID), FOREIGN KEY (thing_id) REFERENCES Things (thing_id), FOREIGN KEY (customer_id) REFERENCES Customers (customer_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Customer_Event_Notes ( Customer_Event_Note_ID INTEGER NOT NULL, Customer_Event_ID INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, PRIMARY KEY (Customer_Event_Note_ID), FOREIGN KEY (Customer_Event_ID) REFERENCES Customer_Events (Customer_Event_ID) ); CREATE TABLE Timed_Status_of_Things ( thing_id INTEGER NOT NULL, Date_and_Date DATETIME NOT NULL, Status_of_Thing_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Date, Status_of_Thing_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id) ); CREATE TABLE Timed_Locations_of_Things ( thing_id INTEGER NOT NULL, Date_and_Time DATETIME NOT NULL, Location_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Time, Location_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id)); INSERT INTO `Customers` (`customer_id`, `customer_details`) VALUES (4, 'Mr. Raul Prosacco')INSERT INTO `Properties` (`property_id`, `property_type_code`, `property_address`, `other_details`) VALUES (24, 'apartment', '85456 Annie Lodge Suite 449', 'USA')INSERT INTO `Residents` (`resident_id`, `property_id`, `date_moved_in`, `date_moved_out`, `other_details`) VALUES (6, 954, '2017-06-17 15:43:33', '2017-12-18 03:46:04', 'Anderson Batz')INSERT INTO `Organizations` (`organization_id`, `parent_organization_id`, `organization_details`) VALUES (7, 7, 'Reinger, Hudson and Nolan Group')INSERT INTO `Services` (`service_id`, `organization_id`, `service_type_code`, `service_details`) VALUES (10, 10, 'Cleanning', 'Satisfied')INSERT INTO `Residents_Services` (`resident_id`, `service_id`, `date_moved_in`, `property_id`, `date_requested`, `date_provided`, `other_details`) VALUES (6, 49, '2017-06-17 15:43:33', 954, '2016-07-25 01:32:23', '2018-02-26 00:27:11', 'Satisfied')INSERT INTO `Things` (`thing_id`, `organization_id`, `Type_of_Thing_Code`, `service_type_code`, `service_details`) VALUES (1, 8, 'Electronics', 'Check', 'Unsatisfied')INSERT INTO `Customer_Events` (`Customer_Event_ID`, `customer_id`, `date_moved_in`, `property_id`, `resident_id`, `thing_id`) VALUES (70, 19, '2015-03-27 12:00:00', 605, 10, 1)INSERT INTO `Customer_Event_Notes` (`Customer_Event_Note_ID`, `Customer_Event_ID`, `service_type_code`, `resident_id`, `property_id`, `date_moved_in`) VALUES (18, 70, 'Cleanning', 58, 107, '2016-08-04 01:06:05')INSERT INTO `Timed_Locations_of_Things` (`thing_id`, `Date_and_Time`, `Location_Code`) VALUES (2, '2016-10-12 12:03:07', '064 Charles Mou')INSERT INTO `Timed_Status_of_Things` (`thing_id`, `Date_and_Date`, `Status_of_Thing_Code`) VALUES (2, '2016-05-27 23:33:34', 'Open')
local_govt_and_lot
SELECT DISTINCT date_moved_in FROM residents
What are the distinct move in dates of the residents?
PRAGMA foreign_keys = ON; CREATE TABLE Customers ( customer_id INTEGER NOT NULL, customer_details VARCHAR(255), PRIMARY KEY (customer_id) ); CREATE TABLE Properties ( property_id INTEGER NOT NULL, property_type_code CHAR(15) NOT NULL, property_address VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (property_id) ); CREATE TABLE Residents ( resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, date_moved_out DATETIME NOT NULL, other_details VARCHAR(255), PRIMARY KEY (resident_id, property_id, date_moved_in), FOREIGN KEY (property_id) REFERENCES Properties (property_id) ); CREATE TABLE Organizations ( organization_id INTEGER NOT NULL, parent_organization_id INTEGER, organization_details VARCHAR(255), PRIMARY KEY (organization_id) ); CREATE TABLE Services ( service_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (service_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Residents_Services ( resident_id INTEGER NOT NULL, service_id INTEGER NOT NULL, date_moved_in DATETIME, property_id INTEGER, date_requested DATETIME, date_provided DATETIME, other_details VARCHAR(255), PRIMARY KEY (resident_id, service_id), FOREIGN KEY (service_id) REFERENCES Services (service_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Things ( thing_id INTEGER NOT NULL, organization_id INTEGER NOT NULL, Type_of_Thing_Code CHAR(15) NOT NULL, service_type_code CHAR(10) NOT NULL, service_details VARCHAR(255), PRIMARY KEY (thing_id), FOREIGN KEY (organization_id) REFERENCES Organizations (organization_id) ); CREATE TABLE Customer_Events ( Customer_Event_ID INTEGER NOT NULL, customer_id INTEGER, date_moved_in DATETIME, property_id INTEGER, resident_id INTEGER, thing_id INTEGER NOT NULL, PRIMARY KEY (Customer_Event_ID), FOREIGN KEY (thing_id) REFERENCES Things (thing_id), FOREIGN KEY (customer_id) REFERENCES Customers (customer_id), FOREIGN KEY (resident_id, property_id, date_moved_in) REFERENCES Residents (resident_id,property_id,date_moved_in) ); CREATE TABLE Customer_Event_Notes ( Customer_Event_Note_ID INTEGER NOT NULL, Customer_Event_ID INTEGER NOT NULL, service_type_code CHAR(15) NOT NULL, resident_id INTEGER NOT NULL, property_id INTEGER NOT NULL, date_moved_in DATETIME NOT NULL, PRIMARY KEY (Customer_Event_Note_ID), FOREIGN KEY (Customer_Event_ID) REFERENCES Customer_Events (Customer_Event_ID) ); CREATE TABLE Timed_Status_of_Things ( thing_id INTEGER NOT NULL, Date_and_Date DATETIME NOT NULL, Status_of_Thing_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Date, Status_of_Thing_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id) ); CREATE TABLE Timed_Locations_of_Things ( thing_id INTEGER NOT NULL, Date_and_Time DATETIME NOT NULL, Location_Code CHAR(15) NOT NULL, PRIMARY KEY (thing_id, Date_and_Time, Location_Code), FOREIGN KEY (thing_id) REFERENCES Things (thing_id)); INSERT INTO `Customers` (`customer_id`, `customer_details`) VALUES (4, 'Mr. Raul Prosacco')INSERT INTO `Properties` (`property_id`, `property_type_code`, `property_address`, `other_details`) VALUES (24, 'apartment', '85456 Annie Lodge Suite 449', 'USA')INSERT INTO `Residents` (`resident_id`, `property_id`, `date_moved_in`, `date_moved_out`, `other_details`) VALUES (6, 954, '2017-06-17 15:43:33', '2017-12-18 03:46:04', 'Anderson Batz')INSERT INTO `Organizations` (`organization_id`, `parent_organization_id`, `organization_details`) VALUES (7, 7, 'Reinger, Hudson and Nolan Group')INSERT INTO `Services` (`service_id`, `organization_id`, `service_type_code`, `service_details`) VALUES (10, 10, 'Cleanning', 'Satisfied')INSERT INTO `Residents_Services` (`resident_id`, `service_id`, `date_moved_in`, `property_id`, `date_requested`, `date_provided`, `other_details`) VALUES (6, 49, '2017-06-17 15:43:33', 954, '2016-07-25 01:32:23', '2018-02-26 00:27:11', 'Satisfied')INSERT INTO `Things` (`thing_id`, `organization_id`, `Type_of_Thing_Code`, `service_type_code`, `service_details`) VALUES (1, 8, 'Electronics', 'Check', 'Unsatisfied')INSERT INTO `Customer_Events` (`Customer_Event_ID`, `customer_id`, `date_moved_in`, `property_id`, `resident_id`, `thing_id`) VALUES (70, 19, '2015-03-27 12:00:00', 605, 10, 1)INSERT INTO `Customer_Event_Notes` (`Customer_Event_Note_ID`, `Customer_Event_ID`, `service_type_code`, `resident_id`, `property_id`, `date_moved_in`) VALUES (18, 70, 'Cleanning', 58, 107, '2016-08-04 01:06:05')INSERT INTO `Timed_Locations_of_Things` (`thing_id`, `Date_and_Time`, `Location_Code`) VALUES (2, '2016-10-12 12:03:07', '064 Charles Mou')INSERT INTO `Timed_Status_of_Things` (`thing_id`, `Date_and_Date`, `Status_of_Thing_Code`) VALUES (2, '2016-05-27 23:33:34', 'Open')
school_player
SELECT count(*) FROM school
How many schools are there?
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT count(*) FROM school
Count the number of schools.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT LOCATION FROM school ORDER BY Enrollment ASC
List the locations of schools in ascending order of enrollment.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT LOCATION FROM school ORDER BY Enrollment ASC
What is the list of school locations sorted in ascending order of school enrollment?
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT LOCATION FROM school ORDER BY Founded DESC
List the locations of schools in descending order of founded year.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT LOCATION FROM school ORDER BY Founded DESC
What is the list of school locations sorted in descending order of school foundation year?
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT Enrollment FROM school WHERE Denomination != "Catholic"
What are the enrollments of schools whose denomination is not "Catholic"?
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT Enrollment FROM school WHERE Denomination != "Catholic"
List the enrollment for each school that does not have "Catholic" as denomination.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT avg(Enrollment) FROM school
What is the average enrollment of schools?
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT avg(Enrollment) FROM school
Take the average of the school enrollment.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT Team FROM player ORDER BY Team ASC
What are the teams of the players, sorted in ascending alphabetical order?
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT Team FROM player ORDER BY Team ASC
Find the team of each player and sort them in ascending alphabetical order.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT count(DISTINCT POSITION) FROM player
How many different positions of players are there?
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT count(DISTINCT POSITION) FROM player
Count the number of distinct player positions.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT Team FROM player ORDER BY Age DESC LIMIT 1
Find the team of the player of the highest age.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT Team FROM player ORDER BY Age DESC LIMIT 1
Which team has the oldest player?
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT Team FROM player ORDER BY Age DESC LIMIT 5
List the teams of the players with the top 5 largest ages.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT Team FROM player ORDER BY Age DESC LIMIT 5
What are the teams that have the 5 oldest players?
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT T1.Team , T2.Location FROM player AS T1 JOIN school AS T2 ON T1.School_ID = T2.School_ID
For each player, show the team and the location of school they belong to.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT T1.Team , T2.Location FROM player AS T1 JOIN school AS T2 ON T1.School_ID = T2.School_ID
What are the team and the location of school each player belongs to?
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT T2.Location FROM player AS T1 JOIN school AS T2 ON T1.School_ID = T2.School_ID GROUP BY T1.School_ID HAVING COUNT(*) > 1
Show the locations of schools that have more than 1 player.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT T2.Location FROM player AS T1 JOIN school AS T2 ON T1.School_ID = T2.School_ID GROUP BY T1.School_ID HAVING COUNT(*) > 1
Which schools have more than 1 player? Give me the school locations.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT T2.Denomination FROM player AS T1 JOIN school AS T2 ON T1.School_ID = T2.School_ID GROUP BY T1.School_ID ORDER BY COUNT(*) DESC LIMIT 1
Show the denomination of the school that has the most players.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT T2.Denomination FROM player AS T1 JOIN school AS T2 ON T1.School_ID = T2.School_ID GROUP BY T1.School_ID ORDER BY COUNT(*) DESC LIMIT 1
What is the denomination of the school the most players belong to?
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT T1.Location , T2.Nickname FROM school AS T1 JOIN school_details AS T2 ON T1.School_ID = T2.School_ID
Show locations and nicknames of schools.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT T1.Location , T2.Nickname FROM school AS T1 JOIN school_details AS T2 ON T1.School_ID = T2.School_ID
What are the location and nickname of each school?
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT Denomination , COUNT(*) FROM school GROUP BY Denomination
Please show different denominations and the corresponding number of schools.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT Denomination , COUNT(*) FROM school GROUP BY Denomination
For each denomination, return the denomination and the count of schools with that denomination.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT Denomination , COUNT(*) FROM school GROUP BY Denomination ORDER BY COUNT(*) DESC
Please show different denominations and the corresponding number of schools in descending order.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT Denomination , COUNT(*) FROM school GROUP BY Denomination ORDER BY COUNT(*) DESC
Order denominations in descending order of the count of schools with the denomination. Return each denomination with the count of schools.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT School_Colors FROM school ORDER BY Enrollment DESC LIMIT 1
List the school color of the school that has the largest enrollment.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT School_Colors FROM school ORDER BY Enrollment DESC LIMIT 1
What is the school color of the school with the largest enrollment?
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT LOCATION FROM school WHERE School_ID NOT IN (SELECT School_ID FROM Player)
List the locations of schools that do not have any player.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT LOCATION FROM school WHERE School_ID NOT IN (SELECT School_ID FROM Player)
Which schools do not have any player? Give me the school locations.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT Denomination FROM school WHERE Founded < 1890 INTERSECT SELECT Denomination FROM school WHERE Founded > 1900
Show the denomination shared by schools founded before 1890 and schools founded after 1900
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT Denomination FROM school WHERE Founded < 1890 INTERSECT SELECT Denomination FROM school WHERE Founded > 1900
What are the denominations used by both schools founded before 1890 and schools founded after 1900?
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT Nickname FROM school_details WHERE Division != "Division 1"
Show the nicknames of schools that are not in division 1.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT Nickname FROM school_details WHERE Division != "Division 1"
What are the nicknames of schools whose division is not 1?
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT Denomination FROM school GROUP BY Denomination HAVING COUNT(*) > 1
Show the denomination shared by more than one school.
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
school_player
SELECT Denomination FROM school GROUP BY Denomination HAVING COUNT(*) > 1
What are the denomination more than one school have?
PRAGMA foreign_keys = ON; CREATE TABLE "school" ( "School_ID" int, "School" text, "Location" text, "Enrollment" real, "Founded" real, "Denomination" text, "Boys_or_Girls" text, "Day_or_Boarding" text, "Year_Entered_Competition" real, "School_Colors" text, PRIMARY KEY ("School_Id") ); CREATE TABLE "school_details" ( "School_ID" int, "Nickname" text, "Colors" text, "League" text, "Class" text, "Division" text, PRIMARY KEY ("School_Id"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "school_performance" ( "School_Id" int, "School_Year" text, "Class_A" text, "Class_AA" text, PRIMARY KEY ("School_Id","School_Year"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); CREATE TABLE "player" ( "Player_ID" int, "Player" text, "Team" text, "Age" int, "Position" text, "School_ID" int, PRIMARY KEY ("Player_ID"), FOREIGN KEY (`School_ID`) REFERENCES `school`(`School_ID`) ); INSERT INTO "school" VALUES (1,"St Aloysius' College","Milsons Point","1200","1879","Catholic","Boys","Day","1929","Royal Blue and Gold"); INSERT INTO "school_details" VALUES (1,"Tigers","Blue and Yellow","DSHA","Flight A","Division 1"); INSERT INTO "school_performance" VALUES (1,"1987-88","Yantis","Blanco"); INSERT INTO "player" VALUES ("1","Timothy Beckham","Tampa Bay Devil Rays",15,"Shortstop",1);
store_product
SELECT DISTINCT District_name FROM district ORDER BY city_area DESC
Find all the distinct district names ordered by city area in descending.
PRAGMA foreign_keys = ON; CREATE TABLE "product" ( "product_id" int, "product" text, "dimensions" text, "dpi" real, "pages_per_minute_color" real, "max_page_size" text, "interface" text, PRIMARY KEY ("product_id") ); CREATE TABLE "store" ( "Store_ID" int, "Store_Name" text, "Type" text, "Area_size" real, "Number_of_product_category" real, "Ranking" int, PRIMARY KEY ("Store_ID") ); CREATE TABLE "district" ( "District_ID" int, "District_name" text, "Headquartered_City" text, "City_Population" real, "City_Area" real, PRIMARY KEY ("District_ID") ); CREATE TABLE "store_product" ( "Store_ID" int, "Product_ID" int, PRIMARY KEY ("Store_ID","Product_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`Product_ID`) REFERENCES `product`(`Product_ID`) ); CREATE TABLE "store_district" ( "Store_ID" int, "District_ID" int, PRIMARY KEY ("Store_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`District_ID`) REFERENCES `district`(`District_ID`) ); INSERT INTO "product" VALUES (1,"Fujitsu fi-6130 A4 Series Scanner","301 x 160 x 158","600","30","A4","USB 2.0"); INSERT INTO "store" VALUES (1,"Miramichi","City Mall","179.84","17811","2"); INSERT INTO "district" VALUES ("1","Attock District","Attock City","94620","20"); INSERT INTO "store_product" VALUES (1,1); INSERT INTO "store_district" VALUES (1,15);
store_product
SELECT DISTINCT District_name FROM district ORDER BY city_area DESC
What are the different district names in order of descending city area?
PRAGMA foreign_keys = ON; CREATE TABLE "product" ( "product_id" int, "product" text, "dimensions" text, "dpi" real, "pages_per_minute_color" real, "max_page_size" text, "interface" text, PRIMARY KEY ("product_id") ); CREATE TABLE "store" ( "Store_ID" int, "Store_Name" text, "Type" text, "Area_size" real, "Number_of_product_category" real, "Ranking" int, PRIMARY KEY ("Store_ID") ); CREATE TABLE "district" ( "District_ID" int, "District_name" text, "Headquartered_City" text, "City_Population" real, "City_Area" real, PRIMARY KEY ("District_ID") ); CREATE TABLE "store_product" ( "Store_ID" int, "Product_ID" int, PRIMARY KEY ("Store_ID","Product_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`Product_ID`) REFERENCES `product`(`Product_ID`) ); CREATE TABLE "store_district" ( "Store_ID" int, "District_ID" int, PRIMARY KEY ("Store_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`District_ID`) REFERENCES `district`(`District_ID`) ); INSERT INTO "product" VALUES (1,"Fujitsu fi-6130 A4 Series Scanner","301 x 160 x 158","600","30","A4","USB 2.0"); INSERT INTO "store" VALUES (1,"Miramichi","City Mall","179.84","17811","2"); INSERT INTO "district" VALUES ("1","Attock District","Attock City","94620","20"); INSERT INTO "store_product" VALUES (1,1); INSERT INTO "store_district" VALUES (1,15);
store_product
SELECT max_page_size FROM product GROUP BY max_page_size HAVING count(*) > 3
Find the list of page size which have more than 3 product listed
PRAGMA foreign_keys = ON; CREATE TABLE "product" ( "product_id" int, "product" text, "dimensions" text, "dpi" real, "pages_per_minute_color" real, "max_page_size" text, "interface" text, PRIMARY KEY ("product_id") ); CREATE TABLE "store" ( "Store_ID" int, "Store_Name" text, "Type" text, "Area_size" real, "Number_of_product_category" real, "Ranking" int, PRIMARY KEY ("Store_ID") ); CREATE TABLE "district" ( "District_ID" int, "District_name" text, "Headquartered_City" text, "City_Population" real, "City_Area" real, PRIMARY KEY ("District_ID") ); CREATE TABLE "store_product" ( "Store_ID" int, "Product_ID" int, PRIMARY KEY ("Store_ID","Product_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`Product_ID`) REFERENCES `product`(`Product_ID`) ); CREATE TABLE "store_district" ( "Store_ID" int, "District_ID" int, PRIMARY KEY ("Store_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`District_ID`) REFERENCES `district`(`District_ID`) ); INSERT INTO "product" VALUES (1,"Fujitsu fi-6130 A4 Series Scanner","301 x 160 x 158","600","30","A4","USB 2.0"); INSERT INTO "store" VALUES (1,"Miramichi","City Mall","179.84","17811","2"); INSERT INTO "district" VALUES ("1","Attock District","Attock City","94620","20"); INSERT INTO "store_product" VALUES (1,1); INSERT INTO "store_district" VALUES (1,15);
store_product
SELECT max_page_size FROM product GROUP BY max_page_size HAVING count(*) > 3
What is the maximum page size for everything that has more than 3 products listed?
PRAGMA foreign_keys = ON; CREATE TABLE "product" ( "product_id" int, "product" text, "dimensions" text, "dpi" real, "pages_per_minute_color" real, "max_page_size" text, "interface" text, PRIMARY KEY ("product_id") ); CREATE TABLE "store" ( "Store_ID" int, "Store_Name" text, "Type" text, "Area_size" real, "Number_of_product_category" real, "Ranking" int, PRIMARY KEY ("Store_ID") ); CREATE TABLE "district" ( "District_ID" int, "District_name" text, "Headquartered_City" text, "City_Population" real, "City_Area" real, PRIMARY KEY ("District_ID") ); CREATE TABLE "store_product" ( "Store_ID" int, "Product_ID" int, PRIMARY KEY ("Store_ID","Product_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`Product_ID`) REFERENCES `product`(`Product_ID`) ); CREATE TABLE "store_district" ( "Store_ID" int, "District_ID" int, PRIMARY KEY ("Store_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`District_ID`) REFERENCES `district`(`District_ID`) ); INSERT INTO "product" VALUES (1,"Fujitsu fi-6130 A4 Series Scanner","301 x 160 x 158","600","30","A4","USB 2.0"); INSERT INTO "store" VALUES (1,"Miramichi","City Mall","179.84","17811","2"); INSERT INTO "district" VALUES ("1","Attock District","Attock City","94620","20"); INSERT INTO "store_product" VALUES (1,1); INSERT INTO "store_district" VALUES (1,15);
store_product
SELECT District_name , City_Population FROM district WHERE City_Population BETWEEN 200000 AND 2000000
Find the name and population of district with population between 200000 and 2000000
PRAGMA foreign_keys = ON; CREATE TABLE "product" ( "product_id" int, "product" text, "dimensions" text, "dpi" real, "pages_per_minute_color" real, "max_page_size" text, "interface" text, PRIMARY KEY ("product_id") ); CREATE TABLE "store" ( "Store_ID" int, "Store_Name" text, "Type" text, "Area_size" real, "Number_of_product_category" real, "Ranking" int, PRIMARY KEY ("Store_ID") ); CREATE TABLE "district" ( "District_ID" int, "District_name" text, "Headquartered_City" text, "City_Population" real, "City_Area" real, PRIMARY KEY ("District_ID") ); CREATE TABLE "store_product" ( "Store_ID" int, "Product_ID" int, PRIMARY KEY ("Store_ID","Product_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`Product_ID`) REFERENCES `product`(`Product_ID`) ); CREATE TABLE "store_district" ( "Store_ID" int, "District_ID" int, PRIMARY KEY ("Store_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`District_ID`) REFERENCES `district`(`District_ID`) ); INSERT INTO "product" VALUES (1,"Fujitsu fi-6130 A4 Series Scanner","301 x 160 x 158","600","30","A4","USB 2.0"); INSERT INTO "store" VALUES (1,"Miramichi","City Mall","179.84","17811","2"); INSERT INTO "district" VALUES ("1","Attock District","Attock City","94620","20"); INSERT INTO "store_product" VALUES (1,1); INSERT INTO "store_district" VALUES (1,15);
store_product
SELECT District_name , City_Population FROM district WHERE City_Population BETWEEN 200000 AND 2000000
What are the district names and city populations for all districts that between 200,000 and 2,000,000 residents?
PRAGMA foreign_keys = ON; CREATE TABLE "product" ( "product_id" int, "product" text, "dimensions" text, "dpi" real, "pages_per_minute_color" real, "max_page_size" text, "interface" text, PRIMARY KEY ("product_id") ); CREATE TABLE "store" ( "Store_ID" int, "Store_Name" text, "Type" text, "Area_size" real, "Number_of_product_category" real, "Ranking" int, PRIMARY KEY ("Store_ID") ); CREATE TABLE "district" ( "District_ID" int, "District_name" text, "Headquartered_City" text, "City_Population" real, "City_Area" real, PRIMARY KEY ("District_ID") ); CREATE TABLE "store_product" ( "Store_ID" int, "Product_ID" int, PRIMARY KEY ("Store_ID","Product_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`Product_ID`) REFERENCES `product`(`Product_ID`) ); CREATE TABLE "store_district" ( "Store_ID" int, "District_ID" int, PRIMARY KEY ("Store_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`District_ID`) REFERENCES `district`(`District_ID`) ); INSERT INTO "product" VALUES (1,"Fujitsu fi-6130 A4 Series Scanner","301 x 160 x 158","600","30","A4","USB 2.0"); INSERT INTO "store" VALUES (1,"Miramichi","City Mall","179.84","17811","2"); INSERT INTO "district" VALUES ("1","Attock District","Attock City","94620","20"); INSERT INTO "store_product" VALUES (1,1); INSERT INTO "store_district" VALUES (1,15);
store_product
SELECT district_name FROM district WHERE city_area > 10 OR City_Population > 100000
Find the name all districts with city area greater than 10 or population larger than 100000
PRAGMA foreign_keys = ON; CREATE TABLE "product" ( "product_id" int, "product" text, "dimensions" text, "dpi" real, "pages_per_minute_color" real, "max_page_size" text, "interface" text, PRIMARY KEY ("product_id") ); CREATE TABLE "store" ( "Store_ID" int, "Store_Name" text, "Type" text, "Area_size" real, "Number_of_product_category" real, "Ranking" int, PRIMARY KEY ("Store_ID") ); CREATE TABLE "district" ( "District_ID" int, "District_name" text, "Headquartered_City" text, "City_Population" real, "City_Area" real, PRIMARY KEY ("District_ID") ); CREATE TABLE "store_product" ( "Store_ID" int, "Product_ID" int, PRIMARY KEY ("Store_ID","Product_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`Product_ID`) REFERENCES `product`(`Product_ID`) ); CREATE TABLE "store_district" ( "Store_ID" int, "District_ID" int, PRIMARY KEY ("Store_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`District_ID`) REFERENCES `district`(`District_ID`) ); INSERT INTO "product" VALUES (1,"Fujitsu fi-6130 A4 Series Scanner","301 x 160 x 158","600","30","A4","USB 2.0"); INSERT INTO "store" VALUES (1,"Miramichi","City Mall","179.84","17811","2"); INSERT INTO "district" VALUES ("1","Attock District","Attock City","94620","20"); INSERT INTO "store_product" VALUES (1,1); INSERT INTO "store_district" VALUES (1,15);
store_product
SELECT district_name FROM district WHERE city_area > 10 OR City_Population > 100000
What are the names of all districts with a city area greater than 10 or have more than 100000 people living there?
PRAGMA foreign_keys = ON; CREATE TABLE "product" ( "product_id" int, "product" text, "dimensions" text, "dpi" real, "pages_per_minute_color" real, "max_page_size" text, "interface" text, PRIMARY KEY ("product_id") ); CREATE TABLE "store" ( "Store_ID" int, "Store_Name" text, "Type" text, "Area_size" real, "Number_of_product_category" real, "Ranking" int, PRIMARY KEY ("Store_ID") ); CREATE TABLE "district" ( "District_ID" int, "District_name" text, "Headquartered_City" text, "City_Population" real, "City_Area" real, PRIMARY KEY ("District_ID") ); CREATE TABLE "store_product" ( "Store_ID" int, "Product_ID" int, PRIMARY KEY ("Store_ID","Product_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`Product_ID`) REFERENCES `product`(`Product_ID`) ); CREATE TABLE "store_district" ( "Store_ID" int, "District_ID" int, PRIMARY KEY ("Store_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`District_ID`) REFERENCES `district`(`District_ID`) ); INSERT INTO "product" VALUES (1,"Fujitsu fi-6130 A4 Series Scanner","301 x 160 x 158","600","30","A4","USB 2.0"); INSERT INTO "store" VALUES (1,"Miramichi","City Mall","179.84","17811","2"); INSERT INTO "district" VALUES ("1","Attock District","Attock City","94620","20"); INSERT INTO "store_product" VALUES (1,1); INSERT INTO "store_district" VALUES (1,15);
store_product
SELECT district_name FROM district ORDER BY city_population DESC LIMIT 1
Which district has the largest population?
PRAGMA foreign_keys = ON; CREATE TABLE "product" ( "product_id" int, "product" text, "dimensions" text, "dpi" real, "pages_per_minute_color" real, "max_page_size" text, "interface" text, PRIMARY KEY ("product_id") ); CREATE TABLE "store" ( "Store_ID" int, "Store_Name" text, "Type" text, "Area_size" real, "Number_of_product_category" real, "Ranking" int, PRIMARY KEY ("Store_ID") ); CREATE TABLE "district" ( "District_ID" int, "District_name" text, "Headquartered_City" text, "City_Population" real, "City_Area" real, PRIMARY KEY ("District_ID") ); CREATE TABLE "store_product" ( "Store_ID" int, "Product_ID" int, PRIMARY KEY ("Store_ID","Product_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`Product_ID`) REFERENCES `product`(`Product_ID`) ); CREATE TABLE "store_district" ( "Store_ID" int, "District_ID" int, PRIMARY KEY ("Store_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`District_ID`) REFERENCES `district`(`District_ID`) ); INSERT INTO "product" VALUES (1,"Fujitsu fi-6130 A4 Series Scanner","301 x 160 x 158","600","30","A4","USB 2.0"); INSERT INTO "store" VALUES (1,"Miramichi","City Mall","179.84","17811","2"); INSERT INTO "district" VALUES ("1","Attock District","Attock City","94620","20"); INSERT INTO "store_product" VALUES (1,1); INSERT INTO "store_district" VALUES (1,15);
store_product
SELECT district_name FROM district ORDER BY city_population DESC LIMIT 1
What is the name of the district with the most residents?
PRAGMA foreign_keys = ON; CREATE TABLE "product" ( "product_id" int, "product" text, "dimensions" text, "dpi" real, "pages_per_minute_color" real, "max_page_size" text, "interface" text, PRIMARY KEY ("product_id") ); CREATE TABLE "store" ( "Store_ID" int, "Store_Name" text, "Type" text, "Area_size" real, "Number_of_product_category" real, "Ranking" int, PRIMARY KEY ("Store_ID") ); CREATE TABLE "district" ( "District_ID" int, "District_name" text, "Headquartered_City" text, "City_Population" real, "City_Area" real, PRIMARY KEY ("District_ID") ); CREATE TABLE "store_product" ( "Store_ID" int, "Product_ID" int, PRIMARY KEY ("Store_ID","Product_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`Product_ID`) REFERENCES `product`(`Product_ID`) ); CREATE TABLE "store_district" ( "Store_ID" int, "District_ID" int, PRIMARY KEY ("Store_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`District_ID`) REFERENCES `district`(`District_ID`) ); INSERT INTO "product" VALUES (1,"Fujitsu fi-6130 A4 Series Scanner","301 x 160 x 158","600","30","A4","USB 2.0"); INSERT INTO "store" VALUES (1,"Miramichi","City Mall","179.84","17811","2"); INSERT INTO "district" VALUES ("1","Attock District","Attock City","94620","20"); INSERT INTO "store_product" VALUES (1,1); INSERT INTO "store_district" VALUES (1,15);
store_product
SELECT district_name FROM district ORDER BY city_area ASC LIMIT 1
Which district has the least area?
PRAGMA foreign_keys = ON; CREATE TABLE "product" ( "product_id" int, "product" text, "dimensions" text, "dpi" real, "pages_per_minute_color" real, "max_page_size" text, "interface" text, PRIMARY KEY ("product_id") ); CREATE TABLE "store" ( "Store_ID" int, "Store_Name" text, "Type" text, "Area_size" real, "Number_of_product_category" real, "Ranking" int, PRIMARY KEY ("Store_ID") ); CREATE TABLE "district" ( "District_ID" int, "District_name" text, "Headquartered_City" text, "City_Population" real, "City_Area" real, PRIMARY KEY ("District_ID") ); CREATE TABLE "store_product" ( "Store_ID" int, "Product_ID" int, PRIMARY KEY ("Store_ID","Product_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`Product_ID`) REFERENCES `product`(`Product_ID`) ); CREATE TABLE "store_district" ( "Store_ID" int, "District_ID" int, PRIMARY KEY ("Store_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`District_ID`) REFERENCES `district`(`District_ID`) ); INSERT INTO "product" VALUES (1,"Fujitsu fi-6130 A4 Series Scanner","301 x 160 x 158","600","30","A4","USB 2.0"); INSERT INTO "store" VALUES (1,"Miramichi","City Mall","179.84","17811","2"); INSERT INTO "district" VALUES ("1","Attock District","Attock City","94620","20"); INSERT INTO "store_product" VALUES (1,1); INSERT INTO "store_district" VALUES (1,15);
store_product
SELECT district_name FROM district ORDER BY city_area ASC LIMIT 1
What is the name of the district with the smallest area?
PRAGMA foreign_keys = ON; CREATE TABLE "product" ( "product_id" int, "product" text, "dimensions" text, "dpi" real, "pages_per_minute_color" real, "max_page_size" text, "interface" text, PRIMARY KEY ("product_id") ); CREATE TABLE "store" ( "Store_ID" int, "Store_Name" text, "Type" text, "Area_size" real, "Number_of_product_category" real, "Ranking" int, PRIMARY KEY ("Store_ID") ); CREATE TABLE "district" ( "District_ID" int, "District_name" text, "Headquartered_City" text, "City_Population" real, "City_Area" real, PRIMARY KEY ("District_ID") ); CREATE TABLE "store_product" ( "Store_ID" int, "Product_ID" int, PRIMARY KEY ("Store_ID","Product_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`Product_ID`) REFERENCES `product`(`Product_ID`) ); CREATE TABLE "store_district" ( "Store_ID" int, "District_ID" int, PRIMARY KEY ("Store_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`District_ID`) REFERENCES `district`(`District_ID`) ); INSERT INTO "product" VALUES (1,"Fujitsu fi-6130 A4 Series Scanner","301 x 160 x 158","600","30","A4","USB 2.0"); INSERT INTO "store" VALUES (1,"Miramichi","City Mall","179.84","17811","2"); INSERT INTO "district" VALUES ("1","Attock District","Attock City","94620","20"); INSERT INTO "store_product" VALUES (1,1); INSERT INTO "store_district" VALUES (1,15);
store_product
SELECT sum(city_population) FROM district ORDER BY city_area DESC LIMIT 3
Find the total population of the top 3 districts with the largest area.
PRAGMA foreign_keys = ON; CREATE TABLE "product" ( "product_id" int, "product" text, "dimensions" text, "dpi" real, "pages_per_minute_color" real, "max_page_size" text, "interface" text, PRIMARY KEY ("product_id") ); CREATE TABLE "store" ( "Store_ID" int, "Store_Name" text, "Type" text, "Area_size" real, "Number_of_product_category" real, "Ranking" int, PRIMARY KEY ("Store_ID") ); CREATE TABLE "district" ( "District_ID" int, "District_name" text, "Headquartered_City" text, "City_Population" real, "City_Area" real, PRIMARY KEY ("District_ID") ); CREATE TABLE "store_product" ( "Store_ID" int, "Product_ID" int, PRIMARY KEY ("Store_ID","Product_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`Product_ID`) REFERENCES `product`(`Product_ID`) ); CREATE TABLE "store_district" ( "Store_ID" int, "District_ID" int, PRIMARY KEY ("Store_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`District_ID`) REFERENCES `district`(`District_ID`) ); INSERT INTO "product" VALUES (1,"Fujitsu fi-6130 A4 Series Scanner","301 x 160 x 158","600","30","A4","USB 2.0"); INSERT INTO "store" VALUES (1,"Miramichi","City Mall","179.84","17811","2"); INSERT INTO "district" VALUES ("1","Attock District","Attock City","94620","20"); INSERT INTO "store_product" VALUES (1,1); INSERT INTO "store_district" VALUES (1,15);
store_product
SELECT sum(city_population) FROM district ORDER BY city_area DESC LIMIT 3
What is the total number of residents for the districts with the 3 largest areas?
PRAGMA foreign_keys = ON; CREATE TABLE "product" ( "product_id" int, "product" text, "dimensions" text, "dpi" real, "pages_per_minute_color" real, "max_page_size" text, "interface" text, PRIMARY KEY ("product_id") ); CREATE TABLE "store" ( "Store_ID" int, "Store_Name" text, "Type" text, "Area_size" real, "Number_of_product_category" real, "Ranking" int, PRIMARY KEY ("Store_ID") ); CREATE TABLE "district" ( "District_ID" int, "District_name" text, "Headquartered_City" text, "City_Population" real, "City_Area" real, PRIMARY KEY ("District_ID") ); CREATE TABLE "store_product" ( "Store_ID" int, "Product_ID" int, PRIMARY KEY ("Store_ID","Product_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`Product_ID`) REFERENCES `product`(`Product_ID`) ); CREATE TABLE "store_district" ( "Store_ID" int, "District_ID" int, PRIMARY KEY ("Store_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`District_ID`) REFERENCES `district`(`District_ID`) ); INSERT INTO "product" VALUES (1,"Fujitsu fi-6130 A4 Series Scanner","301 x 160 x 158","600","30","A4","USB 2.0"); INSERT INTO "store" VALUES (1,"Miramichi","City Mall","179.84","17811","2"); INSERT INTO "district" VALUES ("1","Attock District","Attock City","94620","20"); INSERT INTO "store_product" VALUES (1,1); INSERT INTO "store_district" VALUES (1,15);
store_product
SELECT TYPE , count(*) FROM store GROUP BY TYPE
Find all types of store and number of them.
PRAGMA foreign_keys = ON; CREATE TABLE "product" ( "product_id" int, "product" text, "dimensions" text, "dpi" real, "pages_per_minute_color" real, "max_page_size" text, "interface" text, PRIMARY KEY ("product_id") ); CREATE TABLE "store" ( "Store_ID" int, "Store_Name" text, "Type" text, "Area_size" real, "Number_of_product_category" real, "Ranking" int, PRIMARY KEY ("Store_ID") ); CREATE TABLE "district" ( "District_ID" int, "District_name" text, "Headquartered_City" text, "City_Population" real, "City_Area" real, PRIMARY KEY ("District_ID") ); CREATE TABLE "store_product" ( "Store_ID" int, "Product_ID" int, PRIMARY KEY ("Store_ID","Product_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`Product_ID`) REFERENCES `product`(`Product_ID`) ); CREATE TABLE "store_district" ( "Store_ID" int, "District_ID" int, PRIMARY KEY ("Store_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`District_ID`) REFERENCES `district`(`District_ID`) ); INSERT INTO "product" VALUES (1,"Fujitsu fi-6130 A4 Series Scanner","301 x 160 x 158","600","30","A4","USB 2.0"); INSERT INTO "store" VALUES (1,"Miramichi","City Mall","179.84","17811","2"); INSERT INTO "district" VALUES ("1","Attock District","Attock City","94620","20"); INSERT INTO "store_product" VALUES (1,1); INSERT INTO "store_district" VALUES (1,15);
store_product
SELECT TYPE , count(*) FROM store GROUP BY TYPE
For each type of store, how many of them are there?
PRAGMA foreign_keys = ON; CREATE TABLE "product" ( "product_id" int, "product" text, "dimensions" text, "dpi" real, "pages_per_minute_color" real, "max_page_size" text, "interface" text, PRIMARY KEY ("product_id") ); CREATE TABLE "store" ( "Store_ID" int, "Store_Name" text, "Type" text, "Area_size" real, "Number_of_product_category" real, "Ranking" int, PRIMARY KEY ("Store_ID") ); CREATE TABLE "district" ( "District_ID" int, "District_name" text, "Headquartered_City" text, "City_Population" real, "City_Area" real, PRIMARY KEY ("District_ID") ); CREATE TABLE "store_product" ( "Store_ID" int, "Product_ID" int, PRIMARY KEY ("Store_ID","Product_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`Product_ID`) REFERENCES `product`(`Product_ID`) ); CREATE TABLE "store_district" ( "Store_ID" int, "District_ID" int, PRIMARY KEY ("Store_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`District_ID`) REFERENCES `district`(`District_ID`) ); INSERT INTO "product" VALUES (1,"Fujitsu fi-6130 A4 Series Scanner","301 x 160 x 158","600","30","A4","USB 2.0"); INSERT INTO "store" VALUES (1,"Miramichi","City Mall","179.84","17811","2"); INSERT INTO "district" VALUES ("1","Attock District","Attock City","94620","20"); INSERT INTO "store_product" VALUES (1,1); INSERT INTO "store_district" VALUES (1,15);
store_product
SELECT t1.store_name FROM store AS t1 JOIN store_district AS t2 ON t1.store_id = t2.store_id JOIN district AS t3 ON t2.district_id = t3.district_id WHERE t3.district_name = "Khanewal District"
Find the names of all stores in Khanewal District.
PRAGMA foreign_keys = ON; CREATE TABLE "product" ( "product_id" int, "product" text, "dimensions" text, "dpi" real, "pages_per_minute_color" real, "max_page_size" text, "interface" text, PRIMARY KEY ("product_id") ); CREATE TABLE "store" ( "Store_ID" int, "Store_Name" text, "Type" text, "Area_size" real, "Number_of_product_category" real, "Ranking" int, PRIMARY KEY ("Store_ID") ); CREATE TABLE "district" ( "District_ID" int, "District_name" text, "Headquartered_City" text, "City_Population" real, "City_Area" real, PRIMARY KEY ("District_ID") ); CREATE TABLE "store_product" ( "Store_ID" int, "Product_ID" int, PRIMARY KEY ("Store_ID","Product_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`Product_ID`) REFERENCES `product`(`Product_ID`) ); CREATE TABLE "store_district" ( "Store_ID" int, "District_ID" int, PRIMARY KEY ("Store_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`District_ID`) REFERENCES `district`(`District_ID`) ); INSERT INTO "product" VALUES (1,"Fujitsu fi-6130 A4 Series Scanner","301 x 160 x 158","600","30","A4","USB 2.0"); INSERT INTO "store" VALUES (1,"Miramichi","City Mall","179.84","17811","2"); INSERT INTO "district" VALUES ("1","Attock District","Attock City","94620","20"); INSERT INTO "store_product" VALUES (1,1); INSERT INTO "store_district" VALUES (1,15);
store_product
SELECT t1.store_name FROM store AS t1 JOIN store_district AS t2 ON t1.store_id = t2.store_id JOIN district AS t3 ON t2.district_id = t3.district_id WHERE t3.district_name = "Khanewal District"
What are the names of all the stores located in Khanewal District?
PRAGMA foreign_keys = ON; CREATE TABLE "product" ( "product_id" int, "product" text, "dimensions" text, "dpi" real, "pages_per_minute_color" real, "max_page_size" text, "interface" text, PRIMARY KEY ("product_id") ); CREATE TABLE "store" ( "Store_ID" int, "Store_Name" text, "Type" text, "Area_size" real, "Number_of_product_category" real, "Ranking" int, PRIMARY KEY ("Store_ID") ); CREATE TABLE "district" ( "District_ID" int, "District_name" text, "Headquartered_City" text, "City_Population" real, "City_Area" real, PRIMARY KEY ("District_ID") ); CREATE TABLE "store_product" ( "Store_ID" int, "Product_ID" int, PRIMARY KEY ("Store_ID","Product_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`Product_ID`) REFERENCES `product`(`Product_ID`) ); CREATE TABLE "store_district" ( "Store_ID" int, "District_ID" int, PRIMARY KEY ("Store_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`District_ID`) REFERENCES `district`(`District_ID`) ); INSERT INTO "product" VALUES (1,"Fujitsu fi-6130 A4 Series Scanner","301 x 160 x 158","600","30","A4","USB 2.0"); INSERT INTO "store" VALUES (1,"Miramichi","City Mall","179.84","17811","2"); INSERT INTO "district" VALUES ("1","Attock District","Attock City","94620","20"); INSERT INTO "store_product" VALUES (1,1); INSERT INTO "store_district" VALUES (1,15);
store_product
SELECT t1.store_name FROM store AS t1 JOIN store_district AS t2 ON t1.store_id = t2.store_id WHERE district_id = (SELECT district_id FROM district ORDER BY city_population DESC LIMIT 1)
Find all the stores in the district with the most population.
PRAGMA foreign_keys = ON; CREATE TABLE "product" ( "product_id" int, "product" text, "dimensions" text, "dpi" real, "pages_per_minute_color" real, "max_page_size" text, "interface" text, PRIMARY KEY ("product_id") ); CREATE TABLE "store" ( "Store_ID" int, "Store_Name" text, "Type" text, "Area_size" real, "Number_of_product_category" real, "Ranking" int, PRIMARY KEY ("Store_ID") ); CREATE TABLE "district" ( "District_ID" int, "District_name" text, "Headquartered_City" text, "City_Population" real, "City_Area" real, PRIMARY KEY ("District_ID") ); CREATE TABLE "store_product" ( "Store_ID" int, "Product_ID" int, PRIMARY KEY ("Store_ID","Product_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`Product_ID`) REFERENCES `product`(`Product_ID`) ); CREATE TABLE "store_district" ( "Store_ID" int, "District_ID" int, PRIMARY KEY ("Store_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`District_ID`) REFERENCES `district`(`District_ID`) ); INSERT INTO "product" VALUES (1,"Fujitsu fi-6130 A4 Series Scanner","301 x 160 x 158","600","30","A4","USB 2.0"); INSERT INTO "store" VALUES (1,"Miramichi","City Mall","179.84","17811","2"); INSERT INTO "district" VALUES ("1","Attock District","Attock City","94620","20"); INSERT INTO "store_product" VALUES (1,1); INSERT INTO "store_district" VALUES (1,15);
store_product
SELECT t1.store_name FROM store AS t1 JOIN store_district AS t2 ON t1.store_id = t2.store_id WHERE district_id = (SELECT district_id FROM district ORDER BY city_population DESC LIMIT 1)
What are the names of all the stores in the largest district by population?
PRAGMA foreign_keys = ON; CREATE TABLE "product" ( "product_id" int, "product" text, "dimensions" text, "dpi" real, "pages_per_minute_color" real, "max_page_size" text, "interface" text, PRIMARY KEY ("product_id") ); CREATE TABLE "store" ( "Store_ID" int, "Store_Name" text, "Type" text, "Area_size" real, "Number_of_product_category" real, "Ranking" int, PRIMARY KEY ("Store_ID") ); CREATE TABLE "district" ( "District_ID" int, "District_name" text, "Headquartered_City" text, "City_Population" real, "City_Area" real, PRIMARY KEY ("District_ID") ); CREATE TABLE "store_product" ( "Store_ID" int, "Product_ID" int, PRIMARY KEY ("Store_ID","Product_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`Product_ID`) REFERENCES `product`(`Product_ID`) ); CREATE TABLE "store_district" ( "Store_ID" int, "District_ID" int, PRIMARY KEY ("Store_ID"), FOREIGN KEY (`Store_ID`) REFERENCES `store`(`Store_ID`), FOREIGN KEY (`District_ID`) REFERENCES `district`(`District_ID`) ); INSERT INTO "product" VALUES (1,"Fujitsu fi-6130 A4 Series Scanner","301 x 160 x 158","600","30","A4","USB 2.0"); INSERT INTO "store" VALUES (1,"Miramichi","City Mall","179.84","17811","2"); INSERT INTO "district" VALUES ("1","Attock District","Attock City","94620","20"); INSERT INTO "store_product" VALUES (1,1); INSERT INTO "store_district" VALUES (1,15);