db_id
stringclasses
146 values
question
stringlengths
3
224
sql
stringlengths
18
577
database_schema
stringclasses
146 values
election
Which committees have delegates from both democratic party and liberal party?
SELECT T1.Committee FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T2.Party = "Democratic" INTERSECT SELECT T1.Committee FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T2.Party = "Liberal"
CREATE TABLE "county" ( "County_Id" int, "County_name" text, "Population" real, "Zip_code" text, PRIMARY KEY ("County_Id") ) 3 rows from county table: County_Id County_name Population Zip_code 1 Howard 21000.0 D21 2 Baltimore County 90000.0 D08 3 Colony 79000.0 D02 CREATE TABLE "party" ( "Party_ID" int, "Year" real, "Party" text, "Governor" text, "Lieutenant_Governor" text, "Comptroller" text, "Attorney_General" text, "US_Senate" text, PRIMARY KEY ("Party_ID") ) 3 rows from party table: Party_ID Year Party Governor Lieutenant_Governor Comptroller Attorney_General US_Senate 1 1998.0 Democratic Peter Vallone Sandra Frankel Carl McCall Eliot Spitzer Charles Schumer 2 1998.0 Liberal Betsy McCaughey Ross Jonathan Reiter Carl McCall Eliot Spitzer Charles Schumer 3 2002.0 Democratic Carl McCall Dennis Mehiel Alan Hevesi Eliot Spitzer (no election) CREATE TABLE "election" ( "Election_ID" int, "Counties_Represented" text, "District" int, "Delegate" text, "Party" int, "First_Elected" real, "Committee" text, PRIMARY KEY ("Election_ID"), FOREIGN KEY (`Party`) REFERENCES `party`(`Party_ID`), FOREIGN KEY (`District`) REFERENCES `county`(`County_Id`) ) 3 rows from election table: Election_ID Counties_Represented District Delegate Party First_Elected Committee 1 09.1 9A 1 Bates, Gail H. Gail H. Bates 1 2002.0 Appropriations 2 09.1 9A 1 Miller, Warren E. Warren E. Miller 1 2003.0 Economic Matters 3 12.1 12A 2 DeBoy, Steven J. Sr. Steven J. DeBoy, Sr. 2 2002.0 Appropriations
election
Find the committees that have delegates both from from the democratic party and the liberal party.
SELECT T1.Committee FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T2.Party = "Democratic" INTERSECT SELECT T1.Committee FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T2.Party = "Liberal"
CREATE TABLE "county" ( "County_Id" int, "County_name" text, "Population" real, "Zip_code" text, PRIMARY KEY ("County_Id") ) 3 rows from county table: County_Id County_name Population Zip_code 1 Howard 21000.0 D21 2 Baltimore County 90000.0 D08 3 Colony 79000.0 D02 CREATE TABLE "party" ( "Party_ID" int, "Year" real, "Party" text, "Governor" text, "Lieutenant_Governor" text, "Comptroller" text, "Attorney_General" text, "US_Senate" text, PRIMARY KEY ("Party_ID") ) 3 rows from party table: Party_ID Year Party Governor Lieutenant_Governor Comptroller Attorney_General US_Senate 1 1998.0 Democratic Peter Vallone Sandra Frankel Carl McCall Eliot Spitzer Charles Schumer 2 1998.0 Liberal Betsy McCaughey Ross Jonathan Reiter Carl McCall Eliot Spitzer Charles Schumer 3 2002.0 Democratic Carl McCall Dennis Mehiel Alan Hevesi Eliot Spitzer (no election) CREATE TABLE "election" ( "Election_ID" int, "Counties_Represented" text, "District" int, "Delegate" text, "Party" int, "First_Elected" real, "Committee" text, PRIMARY KEY ("Election_ID"), FOREIGN KEY (`Party`) REFERENCES `party`(`Party_ID`), FOREIGN KEY (`District`) REFERENCES `county`(`County_Id`) ) 3 rows from election table: Election_ID Counties_Represented District Delegate Party First_Elected Committee 1 09.1 9A 1 Bates, Gail H. Gail H. Bates 1 2002.0 Appropriations 2 09.1 9A 1 Miller, Warren E. Warren E. Miller 1 2003.0 Economic Matters 3 12.1 12A 2 DeBoy, Steven J. Sr. Steven J. DeBoy, Sr. 2 2002.0 Appropriations
news_report
How many journalists are there?
SELECT count(*) FROM journalist
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ) 3 rows from event table: Event_ID Date Venue Name Event_Attendance 1 13 October 2008 Marathon Olympia Games Openning 6650 2 11 October 2007 Victoria Government Hearing 369 3 7 October 2010 Motagua Public Debating 1675 CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ) 3 rows from journalist table: journalist_ID Name Nationality Age Years_working 1 Herbert Swindells England 37 10 2 Fred Keenor Wales 27 5 3 George Gilchrist England 28 6 CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") ) 3 rows from news_report table: journalist_ID Event_ID Work_Type 1 3 Screening 11 5 Screening 6 1 Screening
news_report
List the names of journalists in ascending order of years working.
SELECT Name FROM journalist ORDER BY Years_working ASC
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ) 3 rows from event table: Event_ID Date Venue Name Event_Attendance 1 13 October 2008 Marathon Olympia Games Openning 6650 2 11 October 2007 Victoria Government Hearing 369 3 7 October 2010 Motagua Public Debating 1675 CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ) 3 rows from journalist table: journalist_ID Name Nationality Age Years_working 1 Herbert Swindells England 37 10 2 Fred Keenor Wales 27 5 3 George Gilchrist England 28 6 CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") ) 3 rows from news_report table: journalist_ID Event_ID Work_Type 1 3 Screening 11 5 Screening 6 1 Screening
news_report
What are the nationalities and ages of journalists?
SELECT Nationality , Age FROM journalist
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ) 3 rows from event table: Event_ID Date Venue Name Event_Attendance 1 13 October 2008 Marathon Olympia Games Openning 6650 2 11 October 2007 Victoria Government Hearing 369 3 7 October 2010 Motagua Public Debating 1675 CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ) 3 rows from journalist table: journalist_ID Name Nationality Age Years_working 1 Herbert Swindells England 37 10 2 Fred Keenor Wales 27 5 3 George Gilchrist England 28 6 CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") ) 3 rows from news_report table: journalist_ID Event_ID Work_Type 1 3 Screening 11 5 Screening 6 1 Screening
news_report
Show the names of journalists from "England" or "Wales".
SELECT Name FROM journalist WHERE Nationality = "England" OR Nationality = "Wales"
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ) 3 rows from event table: Event_ID Date Venue Name Event_Attendance 1 13 October 2008 Marathon Olympia Games Openning 6650 2 11 October 2007 Victoria Government Hearing 369 3 7 October 2010 Motagua Public Debating 1675 CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ) 3 rows from journalist table: journalist_ID Name Nationality Age Years_working 1 Herbert Swindells England 37 10 2 Fred Keenor Wales 27 5 3 George Gilchrist England 28 6 CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") ) 3 rows from news_report table: journalist_ID Event_ID Work_Type 1 3 Screening 11 5 Screening 6 1 Screening
news_report
What is the average number of years spent working as a journalist?
SELECT avg(Years_working) FROM journalist
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ) 3 rows from event table: Event_ID Date Venue Name Event_Attendance 1 13 October 2008 Marathon Olympia Games Openning 6650 2 11 October 2007 Victoria Government Hearing 369 3 7 October 2010 Motagua Public Debating 1675 CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ) 3 rows from journalist table: journalist_ID Name Nationality Age Years_working 1 Herbert Swindells England 37 10 2 Fred Keenor Wales 27 5 3 George Gilchrist England 28 6 CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") ) 3 rows from news_report table: journalist_ID Event_ID Work_Type 1 3 Screening 11 5 Screening 6 1 Screening
news_report
What is the nationality of the journalist with the largest number of years working?
SELECT Nationality FROM journalist ORDER BY Years_working DESC LIMIT 1
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ) 3 rows from event table: Event_ID Date Venue Name Event_Attendance 1 13 October 2008 Marathon Olympia Games Openning 6650 2 11 October 2007 Victoria Government Hearing 369 3 7 October 2010 Motagua Public Debating 1675 CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ) 3 rows from journalist table: journalist_ID Name Nationality Age Years_working 1 Herbert Swindells England 37 10 2 Fred Keenor Wales 27 5 3 George Gilchrist England 28 6 CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") ) 3 rows from news_report table: journalist_ID Event_ID Work_Type 1 3 Screening 11 5 Screening 6 1 Screening
news_report
Show the different nationalities and the number of journalists of each nationality.
SELECT Nationality , COUNT(*) FROM journalist GROUP BY Nationality
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ) 3 rows from event table: Event_ID Date Venue Name Event_Attendance 1 13 October 2008 Marathon Olympia Games Openning 6650 2 11 October 2007 Victoria Government Hearing 369 3 7 October 2010 Motagua Public Debating 1675 CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ) 3 rows from journalist table: journalist_ID Name Nationality Age Years_working 1 Herbert Swindells England 37 10 2 Fred Keenor Wales 27 5 3 George Gilchrist England 28 6 CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") ) 3 rows from news_report table: journalist_ID Event_ID Work_Type 1 3 Screening 11 5 Screening 6 1 Screening
news_report
Show the most common nationality for journalists.
SELECT Nationality FROM journalist GROUP BY Nationality ORDER BY COUNT(*) DESC LIMIT 1
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ) 3 rows from event table: Event_ID Date Venue Name Event_Attendance 1 13 October 2008 Marathon Olympia Games Openning 6650 2 11 October 2007 Victoria Government Hearing 369 3 7 October 2010 Motagua Public Debating 1675 CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ) 3 rows from journalist table: journalist_ID Name Nationality Age Years_working 1 Herbert Swindells England 37 10 2 Fred Keenor Wales 27 5 3 George Gilchrist England 28 6 CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") ) 3 rows from news_report table: journalist_ID Event_ID Work_Type 1 3 Screening 11 5 Screening 6 1 Screening
news_report
Show the nations that have both journalists with more than 10 years of working and journalists with less than 3 years of working.
SELECT Nationality FROM journalist WHERE Years_working > 10 INTERSECT SELECT Nationality FROM journalist WHERE Years_working < 3
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ) 3 rows from event table: Event_ID Date Venue Name Event_Attendance 1 13 October 2008 Marathon Olympia Games Openning 6650 2 11 October 2007 Victoria Government Hearing 369 3 7 October 2010 Motagua Public Debating 1675 CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ) 3 rows from journalist table: journalist_ID Name Nationality Age Years_working 1 Herbert Swindells England 37 10 2 Fred Keenor Wales 27 5 3 George Gilchrist England 28 6 CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") ) 3 rows from news_report table: journalist_ID Event_ID Work_Type 1 3 Screening 11 5 Screening 6 1 Screening
news_report
Show the dates, places, and names of events in descending order of the attendance.
SELECT Date , Name , venue FROM event ORDER BY Event_Attendance DESC
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ) 3 rows from event table: Event_ID Date Venue Name Event_Attendance 1 13 October 2008 Marathon Olympia Games Openning 6650 2 11 October 2007 Victoria Government Hearing 369 3 7 October 2010 Motagua Public Debating 1675 CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ) 3 rows from journalist table: journalist_ID Name Nationality Age Years_working 1 Herbert Swindells England 37 10 2 Fred Keenor Wales 27 5 3 George Gilchrist England 28 6 CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") ) 3 rows from news_report table: journalist_ID Event_ID Work_Type 1 3 Screening 11 5 Screening 6 1 Screening
news_report
Show the names of journalists and the dates of the events they reported.
SELECT T3.Name , T2.Date FROM news_report AS T1 JOIN event AS T2 ON T1.Event_ID = T2.Event_ID JOIN journalist AS T3 ON T1.journalist_ID = T3.journalist_ID
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ) 3 rows from event table: Event_ID Date Venue Name Event_Attendance 1 13 October 2008 Marathon Olympia Games Openning 6650 2 11 October 2007 Victoria Government Hearing 369 3 7 October 2010 Motagua Public Debating 1675 CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ) 3 rows from journalist table: journalist_ID Name Nationality Age Years_working 1 Herbert Swindells England 37 10 2 Fred Keenor Wales 27 5 3 George Gilchrist England 28 6 CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") ) 3 rows from news_report table: journalist_ID Event_ID Work_Type 1 3 Screening 11 5 Screening 6 1 Screening
news_report
Show the names of journalists and the names of the events they reported in ascending order
SELECT T3.Name , T2.Name FROM news_report AS T1 JOIN event AS T2 ON T1.Event_ID = T2.Event_ID JOIN journalist AS T3 ON T1.journalist_ID = T3.journalist_ID ORDER BY T2.Event_Attendance ASC
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ) 3 rows from event table: Event_ID Date Venue Name Event_Attendance 1 13 October 2008 Marathon Olympia Games Openning 6650 2 11 October 2007 Victoria Government Hearing 369 3 7 October 2010 Motagua Public Debating 1675 CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ) 3 rows from journalist table: journalist_ID Name Nationality Age Years_working 1 Herbert Swindells England 37 10 2 Fred Keenor Wales 27 5 3 George Gilchrist England 28 6 CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") ) 3 rows from news_report table: journalist_ID Event_ID Work_Type 1 3 Screening 11 5 Screening 6 1 Screening
news_report
Show the names of journalists and the number of events they reported.
SELECT T3.Name , COUNT(*) FROM news_report AS T1 JOIN event AS T2 ON T1.Event_ID = T2.Event_ID JOIN journalist AS T3 ON T1.journalist_ID = T3.journalist_ID GROUP BY T3.Name
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ) 3 rows from event table: Event_ID Date Venue Name Event_Attendance 1 13 October 2008 Marathon Olympia Games Openning 6650 2 11 October 2007 Victoria Government Hearing 369 3 7 October 2010 Motagua Public Debating 1675 CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ) 3 rows from journalist table: journalist_ID Name Nationality Age Years_working 1 Herbert Swindells England 37 10 2 Fred Keenor Wales 27 5 3 George Gilchrist England 28 6 CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") ) 3 rows from news_report table: journalist_ID Event_ID Work_Type 1 3 Screening 11 5 Screening 6 1 Screening
news_report
Show the names of journalists that have reported more than one event.
SELECT T3.Name FROM news_report AS T1 JOIN event AS T2 ON T1.Event_ID = T2.Event_ID JOIN journalist AS T3 ON T1.journalist_ID = T3.journalist_ID GROUP BY T3.Name HAVING COUNT(*) > 1
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ) 3 rows from event table: Event_ID Date Venue Name Event_Attendance 1 13 October 2008 Marathon Olympia Games Openning 6650 2 11 October 2007 Victoria Government Hearing 369 3 7 October 2010 Motagua Public Debating 1675 CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ) 3 rows from journalist table: journalist_ID Name Nationality Age Years_working 1 Herbert Swindells England 37 10 2 Fred Keenor Wales 27 5 3 George Gilchrist England 28 6 CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") ) 3 rows from news_report table: journalist_ID Event_ID Work_Type 1 3 Screening 11 5 Screening 6 1 Screening
news_report
List the names of journalists who have not reported any event.
SELECT Name FROM journalist WHERE journalist_ID NOT IN (SELECT journalist_ID FROM news_report)
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ) 3 rows from event table: Event_ID Date Venue Name Event_Attendance 1 13 October 2008 Marathon Olympia Games Openning 6650 2 11 October 2007 Victoria Government Hearing 369 3 7 October 2010 Motagua Public Debating 1675 CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ) 3 rows from journalist table: journalist_ID Name Nationality Age Years_working 1 Herbert Swindells England 37 10 2 Fred Keenor Wales 27 5 3 George Gilchrist England 28 6 CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") ) 3 rows from news_report table: journalist_ID Event_ID Work_Type 1 3 Screening 11 5 Screening 6 1 Screening
news_report
what are the average and maximum attendances of all events?
SELECT avg(Event_Attendance) , max(Event_Attendance) FROM event
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ) 3 rows from event table: Event_ID Date Venue Name Event_Attendance 1 13 October 2008 Marathon Olympia Games Openning 6650 2 11 October 2007 Victoria Government Hearing 369 3 7 October 2010 Motagua Public Debating 1675 CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ) 3 rows from journalist table: journalist_ID Name Nationality Age Years_working 1 Herbert Swindells England 37 10 2 Fred Keenor Wales 27 5 3 George Gilchrist England 28 6 CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") ) 3 rows from news_report table: journalist_ID Event_ID Work_Type 1 3 Screening 11 5 Screening 6 1 Screening
news_report
Find the average age and experience working length of journalists working on different role type.
SELECT avg(t1.age) , avg(Years_working) , t2.work_type FROM journalist AS t1 JOIN news_report AS t2 ON t1.journalist_id = t2.journalist_id GROUP BY t2.work_type
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ) 3 rows from event table: Event_ID Date Venue Name Event_Attendance 1 13 October 2008 Marathon Olympia Games Openning 6650 2 11 October 2007 Victoria Government Hearing 369 3 7 October 2010 Motagua Public Debating 1675 CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ) 3 rows from journalist table: journalist_ID Name Nationality Age Years_working 1 Herbert Swindells England 37 10 2 Fred Keenor Wales 27 5 3 George Gilchrist England 28 6 CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") ) 3 rows from news_report table: journalist_ID Event_ID Work_Type 1 3 Screening 11 5 Screening 6 1 Screening
news_report
List the event venues and names that have the top 2 most number of people attended.
SELECT venue , name FROM event ORDER BY Event_Attendance DESC LIMIT 2
CREATE TABLE "event" ( "Event_ID" int, "Date" text, "Venue" text, "Name" text, "Event_Attendance" int, PRIMARY KEY ("Event_ID") ) 3 rows from event table: Event_ID Date Venue Name Event_Attendance 1 13 October 2008 Marathon Olympia Games Openning 6650 2 11 October 2007 Victoria Government Hearing 369 3 7 October 2010 Motagua Public Debating 1675 CREATE TABLE "journalist" ( "journalist_ID" int, "Name" text, "Nationality" text, "Age" text, "Years_working" int, PRIMARY KEY ("journalist_ID") ) 3 rows from journalist table: journalist_ID Name Nationality Age Years_working 1 Herbert Swindells England 37 10 2 Fred Keenor Wales 27 5 3 George Gilchrist England 28 6 CREATE TABLE "news_report" ( "journalist_ID" int, "Event_ID" int, "Work_Type" text, PRIMARY KEY ("journalist_ID","Event_ID"), FOREIGN KEY ("journalist_ID") REFERENCES `journalist`("journalist_ID"), FOREIGN KEY ("Event_ID") REFERENCES `event`("Event_ID") ) 3 rows from news_report table: journalist_ID Event_ID Work_Type 1 3 Screening 11 5 Screening 6 1 Screening
restaurant_1
Show me all the restaurants.
SELECT ResName FROM Restaurant;
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
What is the address of the restaurant Subway?
SELECT Address FROM Restaurant WHERE ResName = "Subway";
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
What is the rating of the restaurant Subway?
SELECT Rating FROM Restaurant WHERE ResName = "Subway";
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
List all restaurant types.
SELECT ResTypeName FROM Restaurant_Type;
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
What is the description of the restaurant type Sandwich?
SELECT ResTypeDescription FROM Restaurant_Type WHERE ResTypeName = "Sandwich";
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
Which restaurants have highest rating? List the restaurant name and its rating.
SELECT ResName , Rating FROM Restaurant ORDER BY Rating DESC LIMIT 1;
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
What is the age of student Linda Smith?
SELECT Age FROM Student WHERE Fname = "Linda" AND Lname = "Smith";
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
What is the gender of the student Linda Smith?
SELECT Sex FROM Student WHERE Fname = "Linda" AND Lname = "Smith";
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
List all students' first names and last names who majored in 600.
SELECT Fname , Lname FROM Student WHERE Major = 600;
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
Which city does student Linda Smith live in?
SELECT city_code FROM Student WHERE Fname = "Linda" AND Lname = "Smith";
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
Advisor 1121 has how many students?
SELECT count(*) FROM Student WHERE Advisor = 1121;
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
Which Advisor has most of students? List advisor and the number of students.
SELECT Advisor , count(*) FROM Student GROUP BY Advisor ORDER BY count(Advisor) DESC LIMIT 1;
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
Which major has least number of students? List the major and the number of students.
SELECT Major , count(*) FROM Student GROUP BY Major ORDER BY count(Major) ASC LIMIT 1;
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
Which major has between 2 and 30 number of students? List major and the number of students.
SELECT Major , count(*) FROM Student GROUP BY Major HAVING count(Major) BETWEEN 2 AND 30;
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
Which student's age is older than 18 and is majoring in 600? List each student's first and last name.
SELECT Fname , Lname FROM Student WHERE Age > 18 AND Major = 600;
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
List all female students age is older than 18 who is not majoring in 600. List students' first name and last name.
SELECT Fname , Lname FROM Student WHERE Age > 18 AND Major != 600 AND Sex = 'F';
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
How many restaurant is the Sandwich type restaurant?
SELECT count(*) FROM Restaurant JOIN Type_Of_Restaurant ON Restaurant.ResID = Type_Of_Restaurant.ResID JOIN Restaurant_Type ON Type_Of_Restaurant.ResTypeID = Restaurant_Type.ResTypeID GROUP BY Type_Of_Restaurant.ResTypeID HAVING Restaurant_Type.ResTypeName = 'Sandwich'
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
How long does student Linda Smith spend on the restaurant in total?
SELECT sum(Spent) FROM Student JOIN Visits_Restaurant ON Student.StuID = Visits_Restaurant.StuID WHERE Student.Fname = "Linda" AND Student.Lname = "Smith";
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
How many times has the student Linda Smith visited Subway?
SELECT count(*) FROM Student JOIN Visits_Restaurant ON Student.StuID = Visits_Restaurant.StuID JOIN Restaurant ON Visits_Restaurant.ResID = Restaurant.ResID WHERE Student.Fname = "Linda" AND Student.Lname = "Smith" AND Restaurant.ResName = "Subway";
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
When did Linda Smith visit Subway?
SELECT TIME FROM Student JOIN Visits_Restaurant ON Student.StuID = Visits_Restaurant.StuID JOIN Restaurant ON Visits_Restaurant.ResID = Restaurant.ResID WHERE Student.Fname = "Linda" AND Student.Lname = "Smith" AND Restaurant.ResName = "Subway";
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
At which restaurant did the students spend the least amount of time? List restaurant and the time students spent on in total.
SELECT Restaurant.ResName , sum(Visits_Restaurant.Spent) FROM Visits_Restaurant JOIN Restaurant ON Visits_Restaurant.ResID = Restaurant.ResID GROUP BY Restaurant.ResID ORDER BY sum(Visits_Restaurant.Spent) ASC LIMIT 1;
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
restaurant_1
Which student visited restaurant most often? List student's first name and last name.
SELECT Student.Fname , Student.Lname FROM Student JOIN Visits_Restaurant ON Student.StuID = Visits_Restaurant.StuID GROUP BY Student.StuID ORDER BY count(*) DESC LIMIT 1;
CREATE TABLE Student ( StuID INTEGER PRIMARY KEY, LName VARCHAR(12), Fname VARCHAR(12), Age INTEGER, Sex VARCHAR(1), Major INTEGER, Advisor INTEGER, city_code VARCHAR(3) ) 3 rows from Student table: StuID LName Fname Age Sex Major Advisor city_code 1001 Smith Linda 18 F 600 1121 BAL 1002 Kim Tracy 19 F 600 7712 HKG 1003 Jones Shiela 21 F 600 7792 WAS CREATE TABLE Restaurant ( ResID INTEGER PRIMARY KEY, ResName VARCHAR(100), Address VARCHAR(100), Rating INTEGER ) 3 rows from Restaurant table: ResID ResName Address Rating 1 Subway 3233 St Paul St, Baltimore, MD 21218 3 2 Honeygrow 3212 St Paul St, Baltimore, MD 21218 4 CREATE TABLE Type_Of_Restaurant ( ResID INTEGER, ResTypeID INTEGER, FOREIGN KEY(ResID) REFERENCES Restaurant(ResID), FOREIGN KEY(ResTypeID) REFERENCES Restaurant_Type(ResTypeID) ) 3 rows from Type_Of_Restaurant table: ResID ResTypeID 1 1 2 2 CREATE TABLE Restaurant_Type ( ResTypeID INTEGER PRIMARY KEY, ResTypeName VARCHAR(40), ResTypeDescription VARCHAR(100) ) 3 rows from Restaurant_Type table: ResTypeID ResTypeName ResTypeDescription 1 Sandwich Simplest there is. 2 Stir-fry Classic Chinese cooking. CREATE TABLE Visits_Restaurant ( StuID INTEGER, ResID INTEGER, Time TIMESTAMP, Spent FLOAT, FOREIGN KEY(StuID) REFERENCES Student(StuID), FOREIGN KEY(ResID) REFERENCES Restaurant(ResID) ) 3 rows from Visits_Restaurant table: StuID ResID Time Spent 1001 1 2017-10-09 18:15:00 6.53 1032 2 2017-10-08 13:00:30 13.20
customer_deliveries
Find the ids of orders whose status is 'Success'.
SELECT actual_order_id FROM actual_orders WHERE order_status_code = 'Success'
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_price product_description 1 dvds 1322.78 good condition 2 cloth 6402.09 good condition 3 electronics 2511.29 great condition CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ) 3 rows from Addresses table: address_id address_details city zip_postcode state_province_county country 1 92283 Lora Forges Suite 322 Mohrville 271 Nebraska USA 2 17135 Jaida Fork Suite 798 East Brody 940 Colorado USA 3 41099 Crist Prairie Suite 507 Evelinebury 003 Idaho USA CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ) 3 rows from Customers table: customer_id payment_method customer_name customer_phone customer_email date_became_customer 1 Visa Ron Emard 1-382-503-5179x53639 shaniya45@example.net 2011-04-25 22:20:35 2 MasterCard Gabe Schroeder 1-728-537-4293x0885 alexandra91@example.net 2011-10-17 16:08:25 3 Discover Candace Schneider 940.575.3682x7959 tkassulke@example.com 2012-01-11 21:17:01 CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Regular_Orders table: regular_order_id distributer_id 1 12 2 15 3 6 CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Regular_Order_Products table: regular_order_id product_id 5 3 2 3 10 1 CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Actual_Orders table: actual_order_id order_status_code regular_order_id actual_order_date 1 Success 8 2018-03-02 23:26:19 2 Cancel 15 2018-03-02 08:33:39 3 Cancel 4 2018-02-25 10:13:36 CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ) 3 rows from Actual_Order_Products table: actual_order_id product_id 2 1 14 5 13 6 CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_from address_type date_to 5 6 2016-09-06 19:23:46 House 2018-02-25 15:34:58 14 5 2016-12-21 03:49:54 House 2018-03-13 21:20:21 2 2 2014-06-09 06:31:49 Flat 2018-03-02 21:56:40 CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ) 3 rows from Delivery_Routes table: route_id route_name other_route_details 1 Torphy Ltd 16893 Wilderman Terrace\nPort Lucasburgh, ND 55978-5550 2 Heidenreich Group 6534 Cheyenne Trace Suite 242\nKoryburgh, PA 21391-9164 3 Gerhold Inc 70469 Unique Crest\nKatherynville, IA 92263-4974 CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ) 3 rows from Delivery_Route_Locations table: location_code route_id location_address_id location_name 27 City Rd 11 5 Labadie-Crooks 30 Sam Rd 7 13 VonRueden, Schmeler and Fay 67 LV Rd 11 6 Carter, Pfannerstill and Rutherford CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ) 3 rows from Trucks table: truck_id truck_licence_number truck_details 1 58110 Frida 2 33822 Randy 3 17106 Laverna CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Employees table: employee_id employee_address_id employee_name employee_phone 1 4 Kacie 716-650-2081 2 12 Dejuan 211.289.9042 3 1 Leonie 816-890-2580 CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) ) 3 rows from Order_Deliveries table: location_code actual_order_id delivery_status_code driver_employee_id truck_id delivery_date 27 City Rd 11 Ready 6 11 2018-03-21 00:57:22 27 City Rd 1 On Road 4 10 2018-02-26 01:32:49 27 City Rd 3 Ready 1 2 2018-03-08 17:17:12
customer_deliveries
Find the name and price of the product that has been ordered the greatest number of times.
SELECT t1.product_name , t1.product_price FROM products AS t1 JOIN regular_order_products AS t2 ON t1.product_id = t2.product_id GROUP BY t2.product_id ORDER BY count(*) DESC LIMIT 1
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_price product_description 1 dvds 1322.78 good condition 2 cloth 6402.09 good condition 3 electronics 2511.29 great condition CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ) 3 rows from Addresses table: address_id address_details city zip_postcode state_province_county country 1 92283 Lora Forges Suite 322 Mohrville 271 Nebraska USA 2 17135 Jaida Fork Suite 798 East Brody 940 Colorado USA 3 41099 Crist Prairie Suite 507 Evelinebury 003 Idaho USA CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ) 3 rows from Customers table: customer_id payment_method customer_name customer_phone customer_email date_became_customer 1 Visa Ron Emard 1-382-503-5179x53639 shaniya45@example.net 2011-04-25 22:20:35 2 MasterCard Gabe Schroeder 1-728-537-4293x0885 alexandra91@example.net 2011-10-17 16:08:25 3 Discover Candace Schneider 940.575.3682x7959 tkassulke@example.com 2012-01-11 21:17:01 CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Regular_Orders table: regular_order_id distributer_id 1 12 2 15 3 6 CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Regular_Order_Products table: regular_order_id product_id 5 3 2 3 10 1 CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Actual_Orders table: actual_order_id order_status_code regular_order_id actual_order_date 1 Success 8 2018-03-02 23:26:19 2 Cancel 15 2018-03-02 08:33:39 3 Cancel 4 2018-02-25 10:13:36 CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ) 3 rows from Actual_Order_Products table: actual_order_id product_id 2 1 14 5 13 6 CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_from address_type date_to 5 6 2016-09-06 19:23:46 House 2018-02-25 15:34:58 14 5 2016-12-21 03:49:54 House 2018-03-13 21:20:21 2 2 2014-06-09 06:31:49 Flat 2018-03-02 21:56:40 CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ) 3 rows from Delivery_Routes table: route_id route_name other_route_details 1 Torphy Ltd 16893 Wilderman Terrace\nPort Lucasburgh, ND 55978-5550 2 Heidenreich Group 6534 Cheyenne Trace Suite 242\nKoryburgh, PA 21391-9164 3 Gerhold Inc 70469 Unique Crest\nKatherynville, IA 92263-4974 CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ) 3 rows from Delivery_Route_Locations table: location_code route_id location_address_id location_name 27 City Rd 11 5 Labadie-Crooks 30 Sam Rd 7 13 VonRueden, Schmeler and Fay 67 LV Rd 11 6 Carter, Pfannerstill and Rutherford CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ) 3 rows from Trucks table: truck_id truck_licence_number truck_details 1 58110 Frida 2 33822 Randy 3 17106 Laverna CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Employees table: employee_id employee_address_id employee_name employee_phone 1 4 Kacie 716-650-2081 2 12 Dejuan 211.289.9042 3 1 Leonie 816-890-2580 CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) ) 3 rows from Order_Deliveries table: location_code actual_order_id delivery_status_code driver_employee_id truck_id delivery_date 27 City Rd 11 Ready 6 11 2018-03-21 00:57:22 27 City Rd 1 On Road 4 10 2018-02-26 01:32:49 27 City Rd 3 Ready 1 2 2018-03-08 17:17:12
customer_deliveries
Find the number of customers in total.
SELECT count(*) FROM customers
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_price product_description 1 dvds 1322.78 good condition 2 cloth 6402.09 good condition 3 electronics 2511.29 great condition CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ) 3 rows from Addresses table: address_id address_details city zip_postcode state_province_county country 1 92283 Lora Forges Suite 322 Mohrville 271 Nebraska USA 2 17135 Jaida Fork Suite 798 East Brody 940 Colorado USA 3 41099 Crist Prairie Suite 507 Evelinebury 003 Idaho USA CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ) 3 rows from Customers table: customer_id payment_method customer_name customer_phone customer_email date_became_customer 1 Visa Ron Emard 1-382-503-5179x53639 shaniya45@example.net 2011-04-25 22:20:35 2 MasterCard Gabe Schroeder 1-728-537-4293x0885 alexandra91@example.net 2011-10-17 16:08:25 3 Discover Candace Schneider 940.575.3682x7959 tkassulke@example.com 2012-01-11 21:17:01 CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Regular_Orders table: regular_order_id distributer_id 1 12 2 15 3 6 CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Regular_Order_Products table: regular_order_id product_id 5 3 2 3 10 1 CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Actual_Orders table: actual_order_id order_status_code regular_order_id actual_order_date 1 Success 8 2018-03-02 23:26:19 2 Cancel 15 2018-03-02 08:33:39 3 Cancel 4 2018-02-25 10:13:36 CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ) 3 rows from Actual_Order_Products table: actual_order_id product_id 2 1 14 5 13 6 CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_from address_type date_to 5 6 2016-09-06 19:23:46 House 2018-02-25 15:34:58 14 5 2016-12-21 03:49:54 House 2018-03-13 21:20:21 2 2 2014-06-09 06:31:49 Flat 2018-03-02 21:56:40 CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ) 3 rows from Delivery_Routes table: route_id route_name other_route_details 1 Torphy Ltd 16893 Wilderman Terrace\nPort Lucasburgh, ND 55978-5550 2 Heidenreich Group 6534 Cheyenne Trace Suite 242\nKoryburgh, PA 21391-9164 3 Gerhold Inc 70469 Unique Crest\nKatherynville, IA 92263-4974 CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ) 3 rows from Delivery_Route_Locations table: location_code route_id location_address_id location_name 27 City Rd 11 5 Labadie-Crooks 30 Sam Rd 7 13 VonRueden, Schmeler and Fay 67 LV Rd 11 6 Carter, Pfannerstill and Rutherford CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ) 3 rows from Trucks table: truck_id truck_licence_number truck_details 1 58110 Frida 2 33822 Randy 3 17106 Laverna CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Employees table: employee_id employee_address_id employee_name employee_phone 1 4 Kacie 716-650-2081 2 12 Dejuan 211.289.9042 3 1 Leonie 816-890-2580 CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) ) 3 rows from Order_Deliveries table: location_code actual_order_id delivery_status_code driver_employee_id truck_id delivery_date 27 City Rd 11 Ready 6 11 2018-03-21 00:57:22 27 City Rd 1 On Road 4 10 2018-02-26 01:32:49 27 City Rd 3 Ready 1 2 2018-03-08 17:17:12
customer_deliveries
How many different payment methods are there?
SELECT count(DISTINCT payment_method) FROM customers
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_price product_description 1 dvds 1322.78 good condition 2 cloth 6402.09 good condition 3 electronics 2511.29 great condition CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ) 3 rows from Addresses table: address_id address_details city zip_postcode state_province_county country 1 92283 Lora Forges Suite 322 Mohrville 271 Nebraska USA 2 17135 Jaida Fork Suite 798 East Brody 940 Colorado USA 3 41099 Crist Prairie Suite 507 Evelinebury 003 Idaho USA CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ) 3 rows from Customers table: customer_id payment_method customer_name customer_phone customer_email date_became_customer 1 Visa Ron Emard 1-382-503-5179x53639 shaniya45@example.net 2011-04-25 22:20:35 2 MasterCard Gabe Schroeder 1-728-537-4293x0885 alexandra91@example.net 2011-10-17 16:08:25 3 Discover Candace Schneider 940.575.3682x7959 tkassulke@example.com 2012-01-11 21:17:01 CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Regular_Orders table: regular_order_id distributer_id 1 12 2 15 3 6 CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Regular_Order_Products table: regular_order_id product_id 5 3 2 3 10 1 CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Actual_Orders table: actual_order_id order_status_code regular_order_id actual_order_date 1 Success 8 2018-03-02 23:26:19 2 Cancel 15 2018-03-02 08:33:39 3 Cancel 4 2018-02-25 10:13:36 CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ) 3 rows from Actual_Order_Products table: actual_order_id product_id 2 1 14 5 13 6 CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_from address_type date_to 5 6 2016-09-06 19:23:46 House 2018-02-25 15:34:58 14 5 2016-12-21 03:49:54 House 2018-03-13 21:20:21 2 2 2014-06-09 06:31:49 Flat 2018-03-02 21:56:40 CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ) 3 rows from Delivery_Routes table: route_id route_name other_route_details 1 Torphy Ltd 16893 Wilderman Terrace\nPort Lucasburgh, ND 55978-5550 2 Heidenreich Group 6534 Cheyenne Trace Suite 242\nKoryburgh, PA 21391-9164 3 Gerhold Inc 70469 Unique Crest\nKatherynville, IA 92263-4974 CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ) 3 rows from Delivery_Route_Locations table: location_code route_id location_address_id location_name 27 City Rd 11 5 Labadie-Crooks 30 Sam Rd 7 13 VonRueden, Schmeler and Fay 67 LV Rd 11 6 Carter, Pfannerstill and Rutherford CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ) 3 rows from Trucks table: truck_id truck_licence_number truck_details 1 58110 Frida 2 33822 Randy 3 17106 Laverna CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Employees table: employee_id employee_address_id employee_name employee_phone 1 4 Kacie 716-650-2081 2 12 Dejuan 211.289.9042 3 1 Leonie 816-890-2580 CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) ) 3 rows from Order_Deliveries table: location_code actual_order_id delivery_status_code driver_employee_id truck_id delivery_date 27 City Rd 11 Ready 6 11 2018-03-21 00:57:22 27 City Rd 1 On Road 4 10 2018-02-26 01:32:49 27 City Rd 3 Ready 1 2 2018-03-08 17:17:12
customer_deliveries
Show the details of all trucks in the order of their license number.
SELECT truck_details FROM trucks ORDER BY truck_licence_number
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_price product_description 1 dvds 1322.78 good condition 2 cloth 6402.09 good condition 3 electronics 2511.29 great condition CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ) 3 rows from Addresses table: address_id address_details city zip_postcode state_province_county country 1 92283 Lora Forges Suite 322 Mohrville 271 Nebraska USA 2 17135 Jaida Fork Suite 798 East Brody 940 Colorado USA 3 41099 Crist Prairie Suite 507 Evelinebury 003 Idaho USA CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ) 3 rows from Customers table: customer_id payment_method customer_name customer_phone customer_email date_became_customer 1 Visa Ron Emard 1-382-503-5179x53639 shaniya45@example.net 2011-04-25 22:20:35 2 MasterCard Gabe Schroeder 1-728-537-4293x0885 alexandra91@example.net 2011-10-17 16:08:25 3 Discover Candace Schneider 940.575.3682x7959 tkassulke@example.com 2012-01-11 21:17:01 CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Regular_Orders table: regular_order_id distributer_id 1 12 2 15 3 6 CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Regular_Order_Products table: regular_order_id product_id 5 3 2 3 10 1 CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Actual_Orders table: actual_order_id order_status_code regular_order_id actual_order_date 1 Success 8 2018-03-02 23:26:19 2 Cancel 15 2018-03-02 08:33:39 3 Cancel 4 2018-02-25 10:13:36 CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ) 3 rows from Actual_Order_Products table: actual_order_id product_id 2 1 14 5 13 6 CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_from address_type date_to 5 6 2016-09-06 19:23:46 House 2018-02-25 15:34:58 14 5 2016-12-21 03:49:54 House 2018-03-13 21:20:21 2 2 2014-06-09 06:31:49 Flat 2018-03-02 21:56:40 CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ) 3 rows from Delivery_Routes table: route_id route_name other_route_details 1 Torphy Ltd 16893 Wilderman Terrace\nPort Lucasburgh, ND 55978-5550 2 Heidenreich Group 6534 Cheyenne Trace Suite 242\nKoryburgh, PA 21391-9164 3 Gerhold Inc 70469 Unique Crest\nKatherynville, IA 92263-4974 CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ) 3 rows from Delivery_Route_Locations table: location_code route_id location_address_id location_name 27 City Rd 11 5 Labadie-Crooks 30 Sam Rd 7 13 VonRueden, Schmeler and Fay 67 LV Rd 11 6 Carter, Pfannerstill and Rutherford CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ) 3 rows from Trucks table: truck_id truck_licence_number truck_details 1 58110 Frida 2 33822 Randy 3 17106 Laverna CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Employees table: employee_id employee_address_id employee_name employee_phone 1 4 Kacie 716-650-2081 2 12 Dejuan 211.289.9042 3 1 Leonie 816-890-2580 CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) ) 3 rows from Order_Deliveries table: location_code actual_order_id delivery_status_code driver_employee_id truck_id delivery_date 27 City Rd 11 Ready 6 11 2018-03-21 00:57:22 27 City Rd 1 On Road 4 10 2018-02-26 01:32:49 27 City Rd 3 Ready 1 2 2018-03-08 17:17:12
customer_deliveries
Find the name of the most expensive product.
SELECT product_name FROM products ORDER BY product_price DESC LIMIT 1
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_price product_description 1 dvds 1322.78 good condition 2 cloth 6402.09 good condition 3 electronics 2511.29 great condition CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ) 3 rows from Addresses table: address_id address_details city zip_postcode state_province_county country 1 92283 Lora Forges Suite 322 Mohrville 271 Nebraska USA 2 17135 Jaida Fork Suite 798 East Brody 940 Colorado USA 3 41099 Crist Prairie Suite 507 Evelinebury 003 Idaho USA CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ) 3 rows from Customers table: customer_id payment_method customer_name customer_phone customer_email date_became_customer 1 Visa Ron Emard 1-382-503-5179x53639 shaniya45@example.net 2011-04-25 22:20:35 2 MasterCard Gabe Schroeder 1-728-537-4293x0885 alexandra91@example.net 2011-10-17 16:08:25 3 Discover Candace Schneider 940.575.3682x7959 tkassulke@example.com 2012-01-11 21:17:01 CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Regular_Orders table: regular_order_id distributer_id 1 12 2 15 3 6 CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Regular_Order_Products table: regular_order_id product_id 5 3 2 3 10 1 CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Actual_Orders table: actual_order_id order_status_code regular_order_id actual_order_date 1 Success 8 2018-03-02 23:26:19 2 Cancel 15 2018-03-02 08:33:39 3 Cancel 4 2018-02-25 10:13:36 CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ) 3 rows from Actual_Order_Products table: actual_order_id product_id 2 1 14 5 13 6 CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_from address_type date_to 5 6 2016-09-06 19:23:46 House 2018-02-25 15:34:58 14 5 2016-12-21 03:49:54 House 2018-03-13 21:20:21 2 2 2014-06-09 06:31:49 Flat 2018-03-02 21:56:40 CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ) 3 rows from Delivery_Routes table: route_id route_name other_route_details 1 Torphy Ltd 16893 Wilderman Terrace\nPort Lucasburgh, ND 55978-5550 2 Heidenreich Group 6534 Cheyenne Trace Suite 242\nKoryburgh, PA 21391-9164 3 Gerhold Inc 70469 Unique Crest\nKatherynville, IA 92263-4974 CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ) 3 rows from Delivery_Route_Locations table: location_code route_id location_address_id location_name 27 City Rd 11 5 Labadie-Crooks 30 Sam Rd 7 13 VonRueden, Schmeler and Fay 67 LV Rd 11 6 Carter, Pfannerstill and Rutherford CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ) 3 rows from Trucks table: truck_id truck_licence_number truck_details 1 58110 Frida 2 33822 Randy 3 17106 Laverna CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Employees table: employee_id employee_address_id employee_name employee_phone 1 4 Kacie 716-650-2081 2 12 Dejuan 211.289.9042 3 1 Leonie 816-890-2580 CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) ) 3 rows from Order_Deliveries table: location_code actual_order_id delivery_status_code driver_employee_id truck_id delivery_date 27 City Rd 11 Ready 6 11 2018-03-21 00:57:22 27 City Rd 1 On Road 4 10 2018-02-26 01:32:49 27 City Rd 3 Ready 1 2 2018-03-08 17:17:12
customer_deliveries
Find the names of customers who are not living in the state of California.
SELECT customer_name FROM customers EXCEPT SELECT t1.customer_name FROM customers AS t1 JOIN customer_addresses AS t2 ON t1.customer_id = t2.customer_id JOIN addresses AS t3 ON t2.address_id = t3.address_id WHERE t3.state_province_county = 'California'
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_price product_description 1 dvds 1322.78 good condition 2 cloth 6402.09 good condition 3 electronics 2511.29 great condition CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ) 3 rows from Addresses table: address_id address_details city zip_postcode state_province_county country 1 92283 Lora Forges Suite 322 Mohrville 271 Nebraska USA 2 17135 Jaida Fork Suite 798 East Brody 940 Colorado USA 3 41099 Crist Prairie Suite 507 Evelinebury 003 Idaho USA CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ) 3 rows from Customers table: customer_id payment_method customer_name customer_phone customer_email date_became_customer 1 Visa Ron Emard 1-382-503-5179x53639 shaniya45@example.net 2011-04-25 22:20:35 2 MasterCard Gabe Schroeder 1-728-537-4293x0885 alexandra91@example.net 2011-10-17 16:08:25 3 Discover Candace Schneider 940.575.3682x7959 tkassulke@example.com 2012-01-11 21:17:01 CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Regular_Orders table: regular_order_id distributer_id 1 12 2 15 3 6 CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Regular_Order_Products table: regular_order_id product_id 5 3 2 3 10 1 CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Actual_Orders table: actual_order_id order_status_code regular_order_id actual_order_date 1 Success 8 2018-03-02 23:26:19 2 Cancel 15 2018-03-02 08:33:39 3 Cancel 4 2018-02-25 10:13:36 CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ) 3 rows from Actual_Order_Products table: actual_order_id product_id 2 1 14 5 13 6 CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_from address_type date_to 5 6 2016-09-06 19:23:46 House 2018-02-25 15:34:58 14 5 2016-12-21 03:49:54 House 2018-03-13 21:20:21 2 2 2014-06-09 06:31:49 Flat 2018-03-02 21:56:40 CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ) 3 rows from Delivery_Routes table: route_id route_name other_route_details 1 Torphy Ltd 16893 Wilderman Terrace\nPort Lucasburgh, ND 55978-5550 2 Heidenreich Group 6534 Cheyenne Trace Suite 242\nKoryburgh, PA 21391-9164 3 Gerhold Inc 70469 Unique Crest\nKatherynville, IA 92263-4974 CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ) 3 rows from Delivery_Route_Locations table: location_code route_id location_address_id location_name 27 City Rd 11 5 Labadie-Crooks 30 Sam Rd 7 13 VonRueden, Schmeler and Fay 67 LV Rd 11 6 Carter, Pfannerstill and Rutherford CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ) 3 rows from Trucks table: truck_id truck_licence_number truck_details 1 58110 Frida 2 33822 Randy 3 17106 Laverna CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Employees table: employee_id employee_address_id employee_name employee_phone 1 4 Kacie 716-650-2081 2 12 Dejuan 211.289.9042 3 1 Leonie 816-890-2580 CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) ) 3 rows from Order_Deliveries table: location_code actual_order_id delivery_status_code driver_employee_id truck_id delivery_date 27 City Rd 11 Ready 6 11 2018-03-21 00:57:22 27 City Rd 1 On Road 4 10 2018-02-26 01:32:49 27 City Rd 3 Ready 1 2 2018-03-08 17:17:12
customer_deliveries
List the names and emails of customers who payed by Visa card.
SELECT customer_email , customer_name FROM customers WHERE payment_method = 'Visa'
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_price product_description 1 dvds 1322.78 good condition 2 cloth 6402.09 good condition 3 electronics 2511.29 great condition CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ) 3 rows from Addresses table: address_id address_details city zip_postcode state_province_county country 1 92283 Lora Forges Suite 322 Mohrville 271 Nebraska USA 2 17135 Jaida Fork Suite 798 East Brody 940 Colorado USA 3 41099 Crist Prairie Suite 507 Evelinebury 003 Idaho USA CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ) 3 rows from Customers table: customer_id payment_method customer_name customer_phone customer_email date_became_customer 1 Visa Ron Emard 1-382-503-5179x53639 shaniya45@example.net 2011-04-25 22:20:35 2 MasterCard Gabe Schroeder 1-728-537-4293x0885 alexandra91@example.net 2011-10-17 16:08:25 3 Discover Candace Schneider 940.575.3682x7959 tkassulke@example.com 2012-01-11 21:17:01 CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Regular_Orders table: regular_order_id distributer_id 1 12 2 15 3 6 CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Regular_Order_Products table: regular_order_id product_id 5 3 2 3 10 1 CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Actual_Orders table: actual_order_id order_status_code regular_order_id actual_order_date 1 Success 8 2018-03-02 23:26:19 2 Cancel 15 2018-03-02 08:33:39 3 Cancel 4 2018-02-25 10:13:36 CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ) 3 rows from Actual_Order_Products table: actual_order_id product_id 2 1 14 5 13 6 CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_from address_type date_to 5 6 2016-09-06 19:23:46 House 2018-02-25 15:34:58 14 5 2016-12-21 03:49:54 House 2018-03-13 21:20:21 2 2 2014-06-09 06:31:49 Flat 2018-03-02 21:56:40 CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ) 3 rows from Delivery_Routes table: route_id route_name other_route_details 1 Torphy Ltd 16893 Wilderman Terrace\nPort Lucasburgh, ND 55978-5550 2 Heidenreich Group 6534 Cheyenne Trace Suite 242\nKoryburgh, PA 21391-9164 3 Gerhold Inc 70469 Unique Crest\nKatherynville, IA 92263-4974 CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ) 3 rows from Delivery_Route_Locations table: location_code route_id location_address_id location_name 27 City Rd 11 5 Labadie-Crooks 30 Sam Rd 7 13 VonRueden, Schmeler and Fay 67 LV Rd 11 6 Carter, Pfannerstill and Rutherford CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ) 3 rows from Trucks table: truck_id truck_licence_number truck_details 1 58110 Frida 2 33822 Randy 3 17106 Laverna CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Employees table: employee_id employee_address_id employee_name employee_phone 1 4 Kacie 716-650-2081 2 12 Dejuan 211.289.9042 3 1 Leonie 816-890-2580 CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) ) 3 rows from Order_Deliveries table: location_code actual_order_id delivery_status_code driver_employee_id truck_id delivery_date 27 City Rd 11 Ready 6 11 2018-03-21 00:57:22 27 City Rd 1 On Road 4 10 2018-02-26 01:32:49 27 City Rd 3 Ready 1 2 2018-03-08 17:17:12
customer_deliveries
Find the names and phone numbers of customers living in California state.
SELECT t1.customer_name , t1.customer_phone FROM customers AS t1 JOIN customer_addresses AS t2 ON t1.customer_id = t2.customer_id JOIN addresses AS t3 ON t2.address_id = t3.address_id WHERE t3.state_province_county = 'California'
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_price product_description 1 dvds 1322.78 good condition 2 cloth 6402.09 good condition 3 electronics 2511.29 great condition CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ) 3 rows from Addresses table: address_id address_details city zip_postcode state_province_county country 1 92283 Lora Forges Suite 322 Mohrville 271 Nebraska USA 2 17135 Jaida Fork Suite 798 East Brody 940 Colorado USA 3 41099 Crist Prairie Suite 507 Evelinebury 003 Idaho USA CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ) 3 rows from Customers table: customer_id payment_method customer_name customer_phone customer_email date_became_customer 1 Visa Ron Emard 1-382-503-5179x53639 shaniya45@example.net 2011-04-25 22:20:35 2 MasterCard Gabe Schroeder 1-728-537-4293x0885 alexandra91@example.net 2011-10-17 16:08:25 3 Discover Candace Schneider 940.575.3682x7959 tkassulke@example.com 2012-01-11 21:17:01 CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Regular_Orders table: regular_order_id distributer_id 1 12 2 15 3 6 CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Regular_Order_Products table: regular_order_id product_id 5 3 2 3 10 1 CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Actual_Orders table: actual_order_id order_status_code regular_order_id actual_order_date 1 Success 8 2018-03-02 23:26:19 2 Cancel 15 2018-03-02 08:33:39 3 Cancel 4 2018-02-25 10:13:36 CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ) 3 rows from Actual_Order_Products table: actual_order_id product_id 2 1 14 5 13 6 CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_from address_type date_to 5 6 2016-09-06 19:23:46 House 2018-02-25 15:34:58 14 5 2016-12-21 03:49:54 House 2018-03-13 21:20:21 2 2 2014-06-09 06:31:49 Flat 2018-03-02 21:56:40 CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ) 3 rows from Delivery_Routes table: route_id route_name other_route_details 1 Torphy Ltd 16893 Wilderman Terrace\nPort Lucasburgh, ND 55978-5550 2 Heidenreich Group 6534 Cheyenne Trace Suite 242\nKoryburgh, PA 21391-9164 3 Gerhold Inc 70469 Unique Crest\nKatherynville, IA 92263-4974 CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ) 3 rows from Delivery_Route_Locations table: location_code route_id location_address_id location_name 27 City Rd 11 5 Labadie-Crooks 30 Sam Rd 7 13 VonRueden, Schmeler and Fay 67 LV Rd 11 6 Carter, Pfannerstill and Rutherford CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ) 3 rows from Trucks table: truck_id truck_licence_number truck_details 1 58110 Frida 2 33822 Randy 3 17106 Laverna CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Employees table: employee_id employee_address_id employee_name employee_phone 1 4 Kacie 716-650-2081 2 12 Dejuan 211.289.9042 3 1 Leonie 816-890-2580 CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) ) 3 rows from Order_Deliveries table: location_code actual_order_id delivery_status_code driver_employee_id truck_id delivery_date 27 City Rd 11 Ready 6 11 2018-03-21 00:57:22 27 City Rd 1 On Road 4 10 2018-02-26 01:32:49 27 City Rd 3 Ready 1 2 2018-03-08 17:17:12
customer_deliveries
Find the states which do not have any employee in their record.
SELECT state_province_county FROM addresses WHERE address_id NOT IN (SELECT employee_address_id FROM Employees)
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_price product_description 1 dvds 1322.78 good condition 2 cloth 6402.09 good condition 3 electronics 2511.29 great condition CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ) 3 rows from Addresses table: address_id address_details city zip_postcode state_province_county country 1 92283 Lora Forges Suite 322 Mohrville 271 Nebraska USA 2 17135 Jaida Fork Suite 798 East Brody 940 Colorado USA 3 41099 Crist Prairie Suite 507 Evelinebury 003 Idaho USA CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ) 3 rows from Customers table: customer_id payment_method customer_name customer_phone customer_email date_became_customer 1 Visa Ron Emard 1-382-503-5179x53639 shaniya45@example.net 2011-04-25 22:20:35 2 MasterCard Gabe Schroeder 1-728-537-4293x0885 alexandra91@example.net 2011-10-17 16:08:25 3 Discover Candace Schneider 940.575.3682x7959 tkassulke@example.com 2012-01-11 21:17:01 CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Regular_Orders table: regular_order_id distributer_id 1 12 2 15 3 6 CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Regular_Order_Products table: regular_order_id product_id 5 3 2 3 10 1 CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Actual_Orders table: actual_order_id order_status_code regular_order_id actual_order_date 1 Success 8 2018-03-02 23:26:19 2 Cancel 15 2018-03-02 08:33:39 3 Cancel 4 2018-02-25 10:13:36 CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ) 3 rows from Actual_Order_Products table: actual_order_id product_id 2 1 14 5 13 6 CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_from address_type date_to 5 6 2016-09-06 19:23:46 House 2018-02-25 15:34:58 14 5 2016-12-21 03:49:54 House 2018-03-13 21:20:21 2 2 2014-06-09 06:31:49 Flat 2018-03-02 21:56:40 CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ) 3 rows from Delivery_Routes table: route_id route_name other_route_details 1 Torphy Ltd 16893 Wilderman Terrace\nPort Lucasburgh, ND 55978-5550 2 Heidenreich Group 6534 Cheyenne Trace Suite 242\nKoryburgh, PA 21391-9164 3 Gerhold Inc 70469 Unique Crest\nKatherynville, IA 92263-4974 CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ) 3 rows from Delivery_Route_Locations table: location_code route_id location_address_id location_name 27 City Rd 11 5 Labadie-Crooks 30 Sam Rd 7 13 VonRueden, Schmeler and Fay 67 LV Rd 11 6 Carter, Pfannerstill and Rutherford CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ) 3 rows from Trucks table: truck_id truck_licence_number truck_details 1 58110 Frida 2 33822 Randy 3 17106 Laverna CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Employees table: employee_id employee_address_id employee_name employee_phone 1 4 Kacie 716-650-2081 2 12 Dejuan 211.289.9042 3 1 Leonie 816-890-2580 CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) ) 3 rows from Order_Deliveries table: location_code actual_order_id delivery_status_code driver_employee_id truck_id delivery_date 27 City Rd 11 Ready 6 11 2018-03-21 00:57:22 27 City Rd 1 On Road 4 10 2018-02-26 01:32:49 27 City Rd 3 Ready 1 2 2018-03-08 17:17:12
customer_deliveries
List the names, phone numbers, and emails of all customers sorted by their dates of becoming customers.
SELECT customer_name , customer_phone , customer_email FROM Customers ORDER BY date_became_customer
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_price product_description 1 dvds 1322.78 good condition 2 cloth 6402.09 good condition 3 electronics 2511.29 great condition CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ) 3 rows from Addresses table: address_id address_details city zip_postcode state_province_county country 1 92283 Lora Forges Suite 322 Mohrville 271 Nebraska USA 2 17135 Jaida Fork Suite 798 East Brody 940 Colorado USA 3 41099 Crist Prairie Suite 507 Evelinebury 003 Idaho USA CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ) 3 rows from Customers table: customer_id payment_method customer_name customer_phone customer_email date_became_customer 1 Visa Ron Emard 1-382-503-5179x53639 shaniya45@example.net 2011-04-25 22:20:35 2 MasterCard Gabe Schroeder 1-728-537-4293x0885 alexandra91@example.net 2011-10-17 16:08:25 3 Discover Candace Schneider 940.575.3682x7959 tkassulke@example.com 2012-01-11 21:17:01 CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Regular_Orders table: regular_order_id distributer_id 1 12 2 15 3 6 CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Regular_Order_Products table: regular_order_id product_id 5 3 2 3 10 1 CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Actual_Orders table: actual_order_id order_status_code regular_order_id actual_order_date 1 Success 8 2018-03-02 23:26:19 2 Cancel 15 2018-03-02 08:33:39 3 Cancel 4 2018-02-25 10:13:36 CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ) 3 rows from Actual_Order_Products table: actual_order_id product_id 2 1 14 5 13 6 CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_from address_type date_to 5 6 2016-09-06 19:23:46 House 2018-02-25 15:34:58 14 5 2016-12-21 03:49:54 House 2018-03-13 21:20:21 2 2 2014-06-09 06:31:49 Flat 2018-03-02 21:56:40 CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ) 3 rows from Delivery_Routes table: route_id route_name other_route_details 1 Torphy Ltd 16893 Wilderman Terrace\nPort Lucasburgh, ND 55978-5550 2 Heidenreich Group 6534 Cheyenne Trace Suite 242\nKoryburgh, PA 21391-9164 3 Gerhold Inc 70469 Unique Crest\nKatherynville, IA 92263-4974 CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ) 3 rows from Delivery_Route_Locations table: location_code route_id location_address_id location_name 27 City Rd 11 5 Labadie-Crooks 30 Sam Rd 7 13 VonRueden, Schmeler and Fay 67 LV Rd 11 6 Carter, Pfannerstill and Rutherford CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ) 3 rows from Trucks table: truck_id truck_licence_number truck_details 1 58110 Frida 2 33822 Randy 3 17106 Laverna CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Employees table: employee_id employee_address_id employee_name employee_phone 1 4 Kacie 716-650-2081 2 12 Dejuan 211.289.9042 3 1 Leonie 816-890-2580 CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) ) 3 rows from Order_Deliveries table: location_code actual_order_id delivery_status_code driver_employee_id truck_id delivery_date 27 City Rd 11 Ready 6 11 2018-03-21 00:57:22 27 City Rd 1 On Road 4 10 2018-02-26 01:32:49 27 City Rd 3 Ready 1 2 2018-03-08 17:17:12
customer_deliveries
Find the name of the first 5 customers.
SELECT customer_name FROM Customers ORDER BY date_became_customer LIMIT 5
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_price product_description 1 dvds 1322.78 good condition 2 cloth 6402.09 good condition 3 electronics 2511.29 great condition CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ) 3 rows from Addresses table: address_id address_details city zip_postcode state_province_county country 1 92283 Lora Forges Suite 322 Mohrville 271 Nebraska USA 2 17135 Jaida Fork Suite 798 East Brody 940 Colorado USA 3 41099 Crist Prairie Suite 507 Evelinebury 003 Idaho USA CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ) 3 rows from Customers table: customer_id payment_method customer_name customer_phone customer_email date_became_customer 1 Visa Ron Emard 1-382-503-5179x53639 shaniya45@example.net 2011-04-25 22:20:35 2 MasterCard Gabe Schroeder 1-728-537-4293x0885 alexandra91@example.net 2011-10-17 16:08:25 3 Discover Candace Schneider 940.575.3682x7959 tkassulke@example.com 2012-01-11 21:17:01 CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Regular_Orders table: regular_order_id distributer_id 1 12 2 15 3 6 CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Regular_Order_Products table: regular_order_id product_id 5 3 2 3 10 1 CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Actual_Orders table: actual_order_id order_status_code regular_order_id actual_order_date 1 Success 8 2018-03-02 23:26:19 2 Cancel 15 2018-03-02 08:33:39 3 Cancel 4 2018-02-25 10:13:36 CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ) 3 rows from Actual_Order_Products table: actual_order_id product_id 2 1 14 5 13 6 CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_from address_type date_to 5 6 2016-09-06 19:23:46 House 2018-02-25 15:34:58 14 5 2016-12-21 03:49:54 House 2018-03-13 21:20:21 2 2 2014-06-09 06:31:49 Flat 2018-03-02 21:56:40 CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ) 3 rows from Delivery_Routes table: route_id route_name other_route_details 1 Torphy Ltd 16893 Wilderman Terrace\nPort Lucasburgh, ND 55978-5550 2 Heidenreich Group 6534 Cheyenne Trace Suite 242\nKoryburgh, PA 21391-9164 3 Gerhold Inc 70469 Unique Crest\nKatherynville, IA 92263-4974 CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ) 3 rows from Delivery_Route_Locations table: location_code route_id location_address_id location_name 27 City Rd 11 5 Labadie-Crooks 30 Sam Rd 7 13 VonRueden, Schmeler and Fay 67 LV Rd 11 6 Carter, Pfannerstill and Rutherford CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ) 3 rows from Trucks table: truck_id truck_licence_number truck_details 1 58110 Frida 2 33822 Randy 3 17106 Laverna CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Employees table: employee_id employee_address_id employee_name employee_phone 1 4 Kacie 716-650-2081 2 12 Dejuan 211.289.9042 3 1 Leonie 816-890-2580 CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) ) 3 rows from Order_Deliveries table: location_code actual_order_id delivery_status_code driver_employee_id truck_id delivery_date 27 City Rd 11 Ready 6 11 2018-03-21 00:57:22 27 City Rd 1 On Road 4 10 2018-02-26 01:32:49 27 City Rd 3 Ready 1 2 2018-03-08 17:17:12
customer_deliveries
Find the payment method that is used most frequently.
SELECT payment_method FROM Customers GROUP BY payment_method ORDER BY count(*) DESC LIMIT 1
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_price product_description 1 dvds 1322.78 good condition 2 cloth 6402.09 good condition 3 electronics 2511.29 great condition CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ) 3 rows from Addresses table: address_id address_details city zip_postcode state_province_county country 1 92283 Lora Forges Suite 322 Mohrville 271 Nebraska USA 2 17135 Jaida Fork Suite 798 East Brody 940 Colorado USA 3 41099 Crist Prairie Suite 507 Evelinebury 003 Idaho USA CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ) 3 rows from Customers table: customer_id payment_method customer_name customer_phone customer_email date_became_customer 1 Visa Ron Emard 1-382-503-5179x53639 shaniya45@example.net 2011-04-25 22:20:35 2 MasterCard Gabe Schroeder 1-728-537-4293x0885 alexandra91@example.net 2011-10-17 16:08:25 3 Discover Candace Schneider 940.575.3682x7959 tkassulke@example.com 2012-01-11 21:17:01 CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Regular_Orders table: regular_order_id distributer_id 1 12 2 15 3 6 CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Regular_Order_Products table: regular_order_id product_id 5 3 2 3 10 1 CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Actual_Orders table: actual_order_id order_status_code regular_order_id actual_order_date 1 Success 8 2018-03-02 23:26:19 2 Cancel 15 2018-03-02 08:33:39 3 Cancel 4 2018-02-25 10:13:36 CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ) 3 rows from Actual_Order_Products table: actual_order_id product_id 2 1 14 5 13 6 CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_from address_type date_to 5 6 2016-09-06 19:23:46 House 2018-02-25 15:34:58 14 5 2016-12-21 03:49:54 House 2018-03-13 21:20:21 2 2 2014-06-09 06:31:49 Flat 2018-03-02 21:56:40 CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ) 3 rows from Delivery_Routes table: route_id route_name other_route_details 1 Torphy Ltd 16893 Wilderman Terrace\nPort Lucasburgh, ND 55978-5550 2 Heidenreich Group 6534 Cheyenne Trace Suite 242\nKoryburgh, PA 21391-9164 3 Gerhold Inc 70469 Unique Crest\nKatherynville, IA 92263-4974 CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ) 3 rows from Delivery_Route_Locations table: location_code route_id location_address_id location_name 27 City Rd 11 5 Labadie-Crooks 30 Sam Rd 7 13 VonRueden, Schmeler and Fay 67 LV Rd 11 6 Carter, Pfannerstill and Rutherford CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ) 3 rows from Trucks table: truck_id truck_licence_number truck_details 1 58110 Frida 2 33822 Randy 3 17106 Laverna CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Employees table: employee_id employee_address_id employee_name employee_phone 1 4 Kacie 716-650-2081 2 12 Dejuan 211.289.9042 3 1 Leonie 816-890-2580 CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) ) 3 rows from Order_Deliveries table: location_code actual_order_id delivery_status_code driver_employee_id truck_id delivery_date 27 City Rd 11 Ready 6 11 2018-03-21 00:57:22 27 City Rd 1 On Road 4 10 2018-02-26 01:32:49 27 City Rd 3 Ready 1 2 2018-03-08 17:17:12
customer_deliveries
List the names of all routes in alphabetic order.
SELECT route_name FROM Delivery_Routes ORDER BY route_name
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_price product_description 1 dvds 1322.78 good condition 2 cloth 6402.09 good condition 3 electronics 2511.29 great condition CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ) 3 rows from Addresses table: address_id address_details city zip_postcode state_province_county country 1 92283 Lora Forges Suite 322 Mohrville 271 Nebraska USA 2 17135 Jaida Fork Suite 798 East Brody 940 Colorado USA 3 41099 Crist Prairie Suite 507 Evelinebury 003 Idaho USA CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ) 3 rows from Customers table: customer_id payment_method customer_name customer_phone customer_email date_became_customer 1 Visa Ron Emard 1-382-503-5179x53639 shaniya45@example.net 2011-04-25 22:20:35 2 MasterCard Gabe Schroeder 1-728-537-4293x0885 alexandra91@example.net 2011-10-17 16:08:25 3 Discover Candace Schneider 940.575.3682x7959 tkassulke@example.com 2012-01-11 21:17:01 CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Regular_Orders table: regular_order_id distributer_id 1 12 2 15 3 6 CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Regular_Order_Products table: regular_order_id product_id 5 3 2 3 10 1 CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Actual_Orders table: actual_order_id order_status_code regular_order_id actual_order_date 1 Success 8 2018-03-02 23:26:19 2 Cancel 15 2018-03-02 08:33:39 3 Cancel 4 2018-02-25 10:13:36 CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ) 3 rows from Actual_Order_Products table: actual_order_id product_id 2 1 14 5 13 6 CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_from address_type date_to 5 6 2016-09-06 19:23:46 House 2018-02-25 15:34:58 14 5 2016-12-21 03:49:54 House 2018-03-13 21:20:21 2 2 2014-06-09 06:31:49 Flat 2018-03-02 21:56:40 CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ) 3 rows from Delivery_Routes table: route_id route_name other_route_details 1 Torphy Ltd 16893 Wilderman Terrace\nPort Lucasburgh, ND 55978-5550 2 Heidenreich Group 6534 Cheyenne Trace Suite 242\nKoryburgh, PA 21391-9164 3 Gerhold Inc 70469 Unique Crest\nKatherynville, IA 92263-4974 CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ) 3 rows from Delivery_Route_Locations table: location_code route_id location_address_id location_name 27 City Rd 11 5 Labadie-Crooks 30 Sam Rd 7 13 VonRueden, Schmeler and Fay 67 LV Rd 11 6 Carter, Pfannerstill and Rutherford CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ) 3 rows from Trucks table: truck_id truck_licence_number truck_details 1 58110 Frida 2 33822 Randy 3 17106 Laverna CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Employees table: employee_id employee_address_id employee_name employee_phone 1 4 Kacie 716-650-2081 2 12 Dejuan 211.289.9042 3 1 Leonie 816-890-2580 CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) ) 3 rows from Order_Deliveries table: location_code actual_order_id delivery_status_code driver_employee_id truck_id delivery_date 27 City Rd 11 Ready 6 11 2018-03-21 00:57:22 27 City Rd 1 On Road 4 10 2018-02-26 01:32:49 27 City Rd 3 Ready 1 2 2018-03-08 17:17:12
customer_deliveries
Find the name of route that has the highest number of deliveries.
SELECT t1.route_name FROM Delivery_Routes AS t1 JOIN Delivery_Route_Locations AS t2 ON t1.route_id = t2.route_id GROUP BY t1.route_id ORDER BY count(*) DESC LIMIT 1
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_price product_description 1 dvds 1322.78 good condition 2 cloth 6402.09 good condition 3 electronics 2511.29 great condition CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ) 3 rows from Addresses table: address_id address_details city zip_postcode state_province_county country 1 92283 Lora Forges Suite 322 Mohrville 271 Nebraska USA 2 17135 Jaida Fork Suite 798 East Brody 940 Colorado USA 3 41099 Crist Prairie Suite 507 Evelinebury 003 Idaho USA CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ) 3 rows from Customers table: customer_id payment_method customer_name customer_phone customer_email date_became_customer 1 Visa Ron Emard 1-382-503-5179x53639 shaniya45@example.net 2011-04-25 22:20:35 2 MasterCard Gabe Schroeder 1-728-537-4293x0885 alexandra91@example.net 2011-10-17 16:08:25 3 Discover Candace Schneider 940.575.3682x7959 tkassulke@example.com 2012-01-11 21:17:01 CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Regular_Orders table: regular_order_id distributer_id 1 12 2 15 3 6 CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Regular_Order_Products table: regular_order_id product_id 5 3 2 3 10 1 CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Actual_Orders table: actual_order_id order_status_code regular_order_id actual_order_date 1 Success 8 2018-03-02 23:26:19 2 Cancel 15 2018-03-02 08:33:39 3 Cancel 4 2018-02-25 10:13:36 CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ) 3 rows from Actual_Order_Products table: actual_order_id product_id 2 1 14 5 13 6 CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_from address_type date_to 5 6 2016-09-06 19:23:46 House 2018-02-25 15:34:58 14 5 2016-12-21 03:49:54 House 2018-03-13 21:20:21 2 2 2014-06-09 06:31:49 Flat 2018-03-02 21:56:40 CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ) 3 rows from Delivery_Routes table: route_id route_name other_route_details 1 Torphy Ltd 16893 Wilderman Terrace\nPort Lucasburgh, ND 55978-5550 2 Heidenreich Group 6534 Cheyenne Trace Suite 242\nKoryburgh, PA 21391-9164 3 Gerhold Inc 70469 Unique Crest\nKatherynville, IA 92263-4974 CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ) 3 rows from Delivery_Route_Locations table: location_code route_id location_address_id location_name 27 City Rd 11 5 Labadie-Crooks 30 Sam Rd 7 13 VonRueden, Schmeler and Fay 67 LV Rd 11 6 Carter, Pfannerstill and Rutherford CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ) 3 rows from Trucks table: truck_id truck_licence_number truck_details 1 58110 Frida 2 33822 Randy 3 17106 Laverna CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Employees table: employee_id employee_address_id employee_name employee_phone 1 4 Kacie 716-650-2081 2 12 Dejuan 211.289.9042 3 1 Leonie 816-890-2580 CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) ) 3 rows from Order_Deliveries table: location_code actual_order_id delivery_status_code driver_employee_id truck_id delivery_date 27 City Rd 11 Ready 6 11 2018-03-21 00:57:22 27 City Rd 1 On Road 4 10 2018-02-26 01:32:49 27 City Rd 3 Ready 1 2 2018-03-08 17:17:12
customer_deliveries
List the state names and the number of customers living in each state.
SELECT t2.state_province_county , count(*) FROM customer_addresses AS t1 JOIN addresses AS t2 ON t1.address_id = t2.address_id GROUP BY t2.state_province_county
CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_name` VARCHAR(20), `product_price` DECIMAL(19,4), `product_description` VARCHAR(255) ) 3 rows from Products table: product_id product_name product_price product_description 1 dvds 1322.78 good condition 2 cloth 6402.09 good condition 3 electronics 2511.29 great condition CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_details` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ) 3 rows from Addresses table: address_id address_details city zip_postcode state_province_county country 1 92283 Lora Forges Suite 322 Mohrville 271 Nebraska USA 2 17135 Jaida Fork Suite 798 East Brody 940 Colorado USA 3 41099 Crist Prairie Suite 507 Evelinebury 003 Idaho USA CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(10) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `date_became_customer` DATETIME ) 3 rows from Customers table: customer_id payment_method customer_name customer_phone customer_email date_became_customer 1 Visa Ron Emard 1-382-503-5179x53639 shaniya45@example.net 2011-04-25 22:20:35 2 MasterCard Gabe Schroeder 1-728-537-4293x0885 alexandra91@example.net 2011-10-17 16:08:25 3 Discover Candace Schneider 940.575.3682x7959 tkassulke@example.com 2012-01-11 21:17:01 CREATE TABLE `Regular_Orders` ( `regular_order_id` INTEGER PRIMARY KEY, `distributer_id` INTEGER NOT NULL, FOREIGN KEY (`distributer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Regular_Orders table: regular_order_id distributer_id 1 12 2 15 3 6 CREATE TABLE `Regular_Order_Products` ( `regular_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Regular_Order_Products table: regular_order_id product_id 5 3 2 3 10 1 CREATE TABLE `Actual_Orders` ( `actual_order_id` INTEGER PRIMARY KEY, `order_status_code` VARCHAR(10) NOT NULL, `regular_order_id` INTEGER NOT NULL, `actual_order_date` DATETIME, FOREIGN KEY (`regular_order_id` ) REFERENCES `Regular_Orders`(`regular_order_id` ) ) 3 rows from Actual_Orders table: actual_order_id order_status_code regular_order_id actual_order_date 1 Success 8 2018-03-02 23:26:19 2 Cancel 15 2018-03-02 08:33:39 3 Cancel 4 2018-02-25 10:13:36 CREATE TABLE `Actual_Order_Products` ( `actual_order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ) ) 3 rows from Actual_Order_Products table: actual_order_id product_id 2 1 14 5 13 6 CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_from` DATETIME NOT NULL, `address_type` VARCHAR(10) NOT NULL, `date_to` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_from address_type date_to 5 6 2016-09-06 19:23:46 House 2018-02-25 15:34:58 14 5 2016-12-21 03:49:54 House 2018-03-13 21:20:21 2 2 2014-06-09 06:31:49 Flat 2018-03-02 21:56:40 CREATE TABLE `Delivery_Routes` ( `route_id` INTEGER PRIMARY KEY, `route_name` VARCHAR(50), `other_route_details` VARCHAR(255) ) 3 rows from Delivery_Routes table: route_id route_name other_route_details 1 Torphy Ltd 16893 Wilderman Terrace\nPort Lucasburgh, ND 55978-5550 2 Heidenreich Group 6534 Cheyenne Trace Suite 242\nKoryburgh, PA 21391-9164 3 Gerhold Inc 70469 Unique Crest\nKatherynville, IA 92263-4974 CREATE TABLE `Delivery_Route_Locations` ( `location_code` VARCHAR(10) PRIMARY KEY, `route_id` INTEGER NOT NULL, `location_address_id` INTEGER NOT NULL, `location_name` VARCHAR(50), FOREIGN KEY (`location_address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`route_id` ) REFERENCES `Delivery_Routes`(`route_id` ) ) 3 rows from Delivery_Route_Locations table: location_code route_id location_address_id location_name 27 City Rd 11 5 Labadie-Crooks 30 Sam Rd 7 13 VonRueden, Schmeler and Fay 67 LV Rd 11 6 Carter, Pfannerstill and Rutherford CREATE TABLE `Trucks` ( `truck_id` INTEGER PRIMARY KEY, `truck_licence_number` VARCHAR(20), `truck_details` VARCHAR(255) ) 3 rows from Trucks table: truck_id truck_licence_number truck_details 1 58110 Frida 2 33822 Randy 3 17106 Laverna CREATE TABLE `Employees` ( `employee_id` INTEGER PRIMARY KEY, `employee_address_id` INTEGER NOT NULL, `employee_name` VARCHAR(80), `employee_phone` VARCHAR(80), FOREIGN KEY (`employee_address_id` ) REFERENCES `Addresses`(`address_id` ) ) 3 rows from Employees table: employee_id employee_address_id employee_name employee_phone 1 4 Kacie 716-650-2081 2 12 Dejuan 211.289.9042 3 1 Leonie 816-890-2580 CREATE TABLE `Order_Deliveries` ( `location_code` VARCHAR(10) NOT NULL, `actual_order_id` INTEGER NOT NULL, `delivery_status_code` VARCHAR(10) NOT NULL, `driver_employee_id` INTEGER NOT NULL, `truck_id` INTEGER NOT NULL, `delivery_date` DATETIME, FOREIGN KEY (`truck_id` ) REFERENCES `Trucks`(`truck_id` ), FOREIGN KEY (`actual_order_id` ) REFERENCES `Actual_Orders`(`actual_order_id` ), FOREIGN KEY (`location_code` ) REFERENCES `Delivery_Route_Locations`(`location_code` ), FOREIGN KEY (`driver_employee_id` ) REFERENCES `Employees`(`employee_id` ) ) 3 rows from Order_Deliveries table: location_code actual_order_id delivery_status_code driver_employee_id truck_id delivery_date 27 City Rd 11 Ready 6 11 2018-03-21 00:57:22 27 City Rd 1 On Road 4 10 2018-02-26 01:32:49 27 City Rd 3 Ready 1 2 2018-03-08 17:17:12
icfp_1
How many authors are there?
SELECT count(*) FROM authors
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Count the number of authors.
SELECT count(*) FROM authors
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
How many institutions are there?
SELECT count(*) FROM inst
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Count the number of institutions.
SELECT count(*) FROM inst
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
How many papers are published in total?
SELECT count(*) FROM papers
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Count the number of total papers.
SELECT count(*) FROM papers
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
What are the titles of papers published by "Jeremy Gibbons"?
SELECT t3.title FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t1.fname = "Jeremy" AND t1.lname = "Gibbons"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Find the titles of all the papers written by "Jeremy Gibbons"
SELECT t3.title FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t1.fname = "Jeremy" AND t1.lname = "Gibbons"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Find all the papers published by "Aaron Turon".
SELECT t3.title FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t1.fname = "Aaron" AND t1.lname = "Turon"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Find the titles of all the papers written by "Aaron Turon".
SELECT t3.title FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t1.fname = "Aaron" AND t1.lname = "Turon"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
How many papers have "Atsushi Ohori" published?
SELECT count(*) FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t1.fname = "Atsushi" AND t1.lname = "Ohori"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
How many papers are "Atsushi Ohori" the author of?
SELECT count(*) FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t1.fname = "Atsushi" AND t1.lname = "Ohori"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
What is the name of the institution that "Matthias Blume" belongs to?
SELECT DISTINCT t3.name FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t1.fname = "Matthias" AND t1.lname = "Blume"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Which institution is the author "Matthias Blume" belong to? Give me the name of the institution.
SELECT DISTINCT t3.name FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t1.fname = "Matthias" AND t1.lname = "Blume"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Which institution does "Katsuhiro Ueno" belong to?
SELECT DISTINCT t3.name FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t1.fname = "Katsuhiro" AND t1.lname = "Ueno"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
What is the name of the institution the author "Katsuhiro Ueno" belongs to?
SELECT DISTINCT t3.name FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t1.fname = "Katsuhiro" AND t1.lname = "Ueno"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Who belong to the institution "University of Oxford"? Show the first names and last names.
SELECT DISTINCT t1.fname , t1.lname FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t3.name = "University of Oxford"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Find the first names and last names of the authors whose institution affiliation is "University of Oxford".
SELECT DISTINCT t1.fname , t1.lname FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t3.name = "University of Oxford"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Which authors belong to the institution "Google"? Show the first names and last names.
SELECT DISTINCT t1.fname , t1.lname FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t3.name = "Google"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Find the first names and last names of the authors whose institution affiliation is "Google".
SELECT DISTINCT t1.fname , t1.lname FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t3.name = "Google"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
What are the last names of the author of the paper titled "Binders Unbound"?
SELECT t1.lname FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t3.title = "Binders Unbound"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Who is the author of the paper titled "Binders Unbound"? Give me the last name.
SELECT t1.lname FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t3.title = "Binders Unbound"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Find the first and last name of the author(s) who wrote the paper "Nameless, Painless".
SELECT t1.fname , t1.lname FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t3.title = "Nameless , Painless"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
What are the first and last name of the author who published the paper titled "Nameless, Painless"?
SELECT t1.fname , t1.lname FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t3.title = "Nameless , Painless"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
What are the papers published under the institution "Indiana University"?
SELECT DISTINCT t1.title FROM papers AS t1 JOIN authorship AS t2 ON t1.paperid = t2.paperid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t3.name = "Indiana University"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
List the titles of the papers whose authors are from the institution "Indiana University".
SELECT DISTINCT t1.title FROM papers AS t1 JOIN authorship AS t2 ON t1.paperid = t2.paperid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t3.name = "Indiana University"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Find all the papers published by the institution "Google".
SELECT DISTINCT t1.title FROM papers AS t1 JOIN authorship AS t2 ON t1.paperid = t2.paperid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t3.name = "Google"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Which papers were written by authors from the institution "Google"?
SELECT DISTINCT t1.title FROM papers AS t1 JOIN authorship AS t2 ON t1.paperid = t2.paperid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t3.name = "Google"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
How many papers are published by the institution "Tokohu University"?
SELECT count(DISTINCT t1.title) FROM papers AS t1 JOIN authorship AS t2 ON t1.paperid = t2.paperid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t3.name = "Tokohu University"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Find the number of papers published by authors from the institution "Tokohu University".
SELECT count(DISTINCT t1.title) FROM papers AS t1 JOIN authorship AS t2 ON t1.paperid = t2.paperid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t3.name = "Tokohu University"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Find the number of papers published by the institution "University of Pennsylvania".
SELECT count(DISTINCT t1.title) FROM papers AS t1 JOIN authorship AS t2 ON t1.paperid = t2.paperid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t3.name = "University of Pennsylvania"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
How many papers are written by authors from the institution "University of Pennsylvania"?
SELECT count(DISTINCT t1.title) FROM papers AS t1 JOIN authorship AS t2 ON t1.paperid = t2.paperid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t3.name = "University of Pennsylvania"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Find the papers which have "Olin Shivers" as an author.
SELECT t3.title FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t1.fname = "Olin" AND t1.lname = "Shivers"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Which papers did the author "Olin Shivers" write? Give me the paper titles.
SELECT t3.title FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t1.fname = "Olin" AND t1.lname = "Shivers"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Which papers have "Stephanie Weirich" as an author?
SELECT t3.title FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t1.fname = "Stephanie" AND t1.lname = "Weirich"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Find the titles of the papers the author "Stephanie Weirich" wrote.
SELECT t3.title FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid WHERE t1.fname = "Stephanie" AND t1.lname = "Weirich"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Which paper is published in an institution in "USA" and have "Turon" as its second author?
SELECT t3.title FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid JOIN inst AS t4 ON t2.instid = t4.instid WHERE t4.country = "USA" AND t2.authorder = 2 AND t1.lname = "Turon"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Find papers whose second author has last name "Turon" and is affiliated with an institution in the country "USA".
SELECT t3.title FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid JOIN inst AS t4 ON t2.instid = t4.instid WHERE t4.country = "USA" AND t2.authorder = 2 AND t1.lname = "Turon"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Find the titles of papers whose first author is affiliated with an institution in the country "Japan" and has last name "Ohori"?
SELECT t3.title FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid JOIN inst AS t4 ON t2.instid = t4.instid WHERE t4.country = "Japan" AND t2.authorder = 1 AND t1.lname = "Ohori"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Which papers' first author is affiliated with an institution in the country "Japan" and has last name "Ohori"? Give me the titles of the papers.
SELECT t3.title FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid JOIN inst AS t4 ON t2.instid = t4.instid WHERE t4.country = "Japan" AND t2.authorder = 1 AND t1.lname = "Ohori"
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
What is the last name of the author that has published the most papers?
SELECT t1.lname FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid GROUP BY t1.fname , t1.lname ORDER BY count(*) DESC LIMIT 1
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1
icfp_1
Which author has written the most papers? Find his or her last name.
SELECT t1.lname FROM authors AS t1 JOIN authorship AS t2 ON t1.authid = t2.authid JOIN papers AS t3 ON t2.paperid = t3.paperid GROUP BY t1.fname , t1.lname ORDER BY count(*) DESC LIMIT 1
CREATE TABLE Inst ( instID INTEGER, name TEXT, country TEXT, -- the home country of the institution (this is obviously an impoverished model) PRIMARY KEY (instID) ) 3 rows from Inst table: instID name country 1000 University of Oxford UK 1010 Northeastern University USA 1020 Indiana University USA CREATE TABLE Authors ( authID INTEGER, lname TEXT, fname TEXT, PRIMARY KEY (authID) ) 3 rows from Authors table: authID lname fname 50 Gibbons Jeremy 51 Hinze Ralf 52 James Daniel W. H. CREATE TABLE Papers ( paperID INTEGER, title TEXT, PRIMARY KEY (paperID) ) 3 rows from Papers table: paperID title 200 Just do it: Simple Monadic Equational Reasoning 201 Proving the Unique Fixed-Point Principle Correct: An Adventure with Category Theory 202 Functional Pearl: Modular Rollback through Control Logging CREATE TABLE Authorship ( authID INTEGER, instID INTEGER, paperID INTEGER, authOrder INTEGER, PRIMARY KEY (authID, instID, paperID), FOREIGN KEY (authID) REFERENCES Authors (authID), FOREIGN KEY (instID) REFERENCES Inst (instID), FOREIGN KEY (paperID) REFERENCES Papers (paperID) ) 3 rows from Authorship table: authID instID paperID authOrder 50 1000 200 1 51 1000 200 2 51 1000 201 1