db_id
stringclasses
146 values
question
stringlengths
3
224
sql
stringlengths
18
577
database_schema
stringclasses
146 values
game_1
How many different types of sports do we offer?
SELECT count(DISTINCT sportname) FROM Sportsinfo
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
How many students play sports?
SELECT count(DISTINCT StuID) FROM Sportsinfo
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
How many different students are involved in sports?
SELECT count(DISTINCT StuID) FROM Sportsinfo
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
List ids for all student who are on scholarship.
SELECT StuID FROM Sportsinfo WHERE onscholarship = 'Y'
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What are the ids for all sporty students who are on scholarship?
SELECT StuID FROM Sportsinfo WHERE onscholarship = 'Y'
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Show last names for all student who are on scholarship.
SELECT T2.Lname FROM Sportsinfo AS T1 JOIN Student AS T2 ON T1.StuID = T2.StuID WHERE T1.onscholarship = 'Y'
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What are the last names for all scholarship students?
SELECT T2.Lname FROM Sportsinfo AS T1 JOIN Student AS T2 ON T1.StuID = T2.StuID WHERE T1.onscholarship = 'Y'
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
How many games are played for all students?
SELECT sum(gamesplayed) FROM Sportsinfo
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What is the total number of games played?
SELECT sum(gamesplayed) FROM Sportsinfo
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
How many games are played for all football games by students on scholarship?
SELECT sum(gamesplayed) FROM Sportsinfo WHERE sportname = "Football" AND onscholarship = 'Y'
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What is the total number of all football games played by scholarship students?
SELECT sum(gamesplayed) FROM Sportsinfo WHERE sportname = "Football" AND onscholarship = 'Y'
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Show all sport name and the number of students.
SELECT sportname , count(*) FROM Sportsinfo GROUP BY sportname
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
How many students play each sport?
SELECT sportname , count(*) FROM Sportsinfo GROUP BY sportname
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Show all student IDs with the number of sports and total number of games played
SELECT StuID , count(*) , sum(gamesplayed) FROM Sportsinfo GROUP BY StuID
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What are the ids of all students along with how many sports and games did they play?
SELECT StuID , count(*) , sum(gamesplayed) FROM Sportsinfo GROUP BY StuID
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Show all student IDs with more than total 10 hours per week on all sports played.
SELECT StuID FROM Sportsinfo GROUP BY StuID HAVING sum(hoursperweek) > 10
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What are the student IDs for everybody who worked for more than 10 hours per week on all sports?
SELECT StuID FROM Sportsinfo GROUP BY StuID HAVING sum(hoursperweek) > 10
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What is the first name and last name of the student who have most number of sports?
SELECT T2.Fname , T2.Lname FROM Sportsinfo AS T1 JOIN Student AS T2 ON T1.StuID = T2.StuID GROUP BY T1.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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What is the first and last name of the student who played the most sports?
SELECT T2.Fname , T2.Lname FROM Sportsinfo AS T1 JOIN Student AS T2 ON T1.StuID = T2.StuID GROUP BY T1.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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Which sport has most number of students on scholarship?
SELECT sportname FROM Sportsinfo WHERE onscholarship = 'Y' GROUP BY sportname 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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What is the sport with the most scholarship students?
SELECT sportname FROM Sportsinfo WHERE onscholarship = 'Y' GROUP BY sportname 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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Show student ids who don't have any sports.
SELECT StuID FROM Student EXCEPT SELECT StuID FROM Sportsinfo
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What are the ids of all students who don't play sports?
SELECT StuID FROM Student EXCEPT SELECT StuID FROM Sportsinfo
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Show student ids who are on scholarship and have major 600.
SELECT StuID FROM Student WHERE major = 600 INTERSECT SELECT StuID FROM Sportsinfo WHERE onscholarship = 'Y'
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What are the student ids for those on scholarship in major number 600?
SELECT StuID FROM Student WHERE major = 600 INTERSECT SELECT StuID FROM Sportsinfo WHERE onscholarship = 'Y'
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Show student ids who are female and play football.
SELECT StuID FROM Student WHERE sex = 'F' INTERSECT SELECT StuID FROM Sportsinfo WHERE sportname = "Football"
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What are the ids of all female students who play football?
SELECT StuID FROM Student WHERE sex = 'F' INTERSECT SELECT StuID FROM Sportsinfo WHERE sportname = "Football"
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Show all male student ids who don't play football.
SELECT StuID FROM Student WHERE sex = 'M' EXCEPT SELECT StuID FROM Sportsinfo WHERE sportname = "Football"
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What are the ids of all male students who do not play football?
SELECT StuID FROM Student WHERE sex = 'M' EXCEPT SELECT StuID FROM Sportsinfo WHERE sportname = "Football"
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Show total hours per week and number of games played for student David Shieber.
SELECT sum(hoursperweek) , sum(gamesplayed) FROM Sportsinfo AS T1 JOIN Student AS T2 ON T1.StuID = T2.StuID WHERE T2.Fname = "David" AND T2.Lname = "Shieber"
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What is the total number of hours per work and number of games played by David Shieber?
SELECT sum(hoursperweek) , sum(gamesplayed) FROM Sportsinfo AS T1 JOIN Student AS T2 ON T1.StuID = T2.StuID WHERE T2.Fname = "David" AND T2.Lname = "Shieber"
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Show total hours per week and number of games played for students under 20.
SELECT sum(hoursperweek) , sum(gamesplayed) FROM Sportsinfo AS T1 JOIN Student AS T2 ON T1.StuID = T2.StuID WHERE T2.age < 20
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What is the total number of hours per week and number of games played by students under 20?
SELECT sum(hoursperweek) , sum(gamesplayed) FROM Sportsinfo AS T1 JOIN Student AS T2 ON T1.StuID = T2.StuID WHERE T2.age < 20
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
How many students play video games?
SELECT count(DISTINCT StuID) FROM Plays_games
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
How many different students play games?
SELECT count(DISTINCT StuID) FROM Plays_games
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Show ids of students who don't play video game.
SELECT StuID FROM Student EXCEPT SELECT StuID FROM Plays_games
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What are the ids of all students who are not video game players?
SELECT StuID FROM Student EXCEPT SELECT StuID FROM Plays_games
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Show ids of students who play video game and play sports.
SELECT StuID FROM Sportsinfo INTERSECT SELECT StuID FROM Plays_games
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What are the ids of all students who played video games and sports?
SELECT StuID FROM Sportsinfo INTERSECT SELECT StuID FROM Plays_games
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Show all game ids and the number of hours played.
SELECT gameid , sum(hours_played) FROM Plays_games GROUP BY gameid
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What are ids and total number of hours played for each game?
SELECT gameid , sum(hours_played) FROM Plays_games GROUP BY gameid
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Show all student ids and the number of hours played.
SELECT Stuid , sum(hours_played) FROM Plays_games GROUP BY Stuid
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What are the ids of all students and number of hours played?
SELECT Stuid , sum(hours_played) FROM Plays_games GROUP BY Stuid
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Show the game name that has most number of hours played.
SELECT gname FROM Plays_games AS T1 JOIN Video_games AS T2 ON T1.gameid = T2.gameid GROUP BY T1.gameid ORDER BY sum(hours_played) 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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What is the name of the game that has been played the most?
SELECT gname FROM Plays_games AS T1 JOIN Video_games AS T2 ON T1.gameid = T2.gameid GROUP BY T1.gameid ORDER BY sum(hours_played) 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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Show all game names played by at least 1000 hours.
SELECT gname FROM Plays_games AS T1 JOIN Video_games AS T2 ON T1.gameid = T2.gameid GROUP BY T1.gameid HAVING sum(hours_played) >= 1000
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What are the names of all the games that have been played for at least 1000 hours?
SELECT gname FROM Plays_games AS T1 JOIN Video_games AS T2 ON T1.gameid = T2.gameid GROUP BY T1.gameid HAVING sum(hours_played) >= 1000
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Show all game names played by Linda Smith
SELECT Gname FROM Plays_games AS T1 JOIN Video_games AS T2 ON T1.gameid = T2.gameid JOIN Student AS T3 ON T3.Stuid = T1.Stuid WHERE T3.Lname = "Smith" AND T3.Fname = "Linda"
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What are the names of all games played by Linda Smith?
SELECT Gname FROM Plays_games AS T1 JOIN Video_games AS T2 ON T1.gameid = T2.gameid JOIN Student AS T3 ON T3.Stuid = T1.Stuid WHERE T3.Lname = "Smith" AND T3.Fname = "Linda"
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Find the last and first name of students who are playing Football or Lacrosse.
SELECT T2.lname , T2.fname FROM SportsInfo AS T1 JOIN Student AS T2 ON T1.StuID = T2.StuID WHERE T1.SportName = "Football" OR T1.SportName = "Lacrosse"
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What is the first and last name of all students who play Football or Lacrosse?
SELECT T2.lname , T2.fname FROM SportsInfo AS T1 JOIN Student AS T2 ON T1.StuID = T2.StuID WHERE T1.SportName = "Football" OR T1.SportName = "Lacrosse"
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Find the first name and age of the students who are playing both Football and Lacrosse.
SELECT fname , age FROM Student WHERE StuID IN (SELECT StuID FROM Sportsinfo WHERE SportName = "Football" INTERSECT SELECT StuID FROM Sportsinfo WHERE SportName = "Lacrosse")
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
What are the first names and ages of all students who are playing both Football and Lacrosse?
SELECT fname , age FROM Student WHERE StuID IN (SELECT StuID FROM Sportsinfo WHERE SportName = "Football" INTERSECT SELECT StuID FROM Sportsinfo WHERE SportName = "Lacrosse")
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
Find the last name and gender of the students who are playing both Call of Destiny and Works of Widenius games.
SELECT lname , sex FROM Student WHERE StuID IN (SELECT T1.StuID FROM Plays_games AS T1 JOIN Video_games AS T2 ON T1.GameID = T2.GameID WHERE T2.Gname = "Call of Destiny" INTERSECT SELECT T1.StuID FROM Plays_games AS T1 JOIN Video_games AS T2 ON T1.GameID = T2.GameID WHERE T2.Gname = "Works of Widenius")
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
game_1
what is the last name and gender of all students who played both Call of Destiny and Works of Widenius?
SELECT lname , sex FROM Student WHERE StuID IN (SELECT T1.StuID FROM Plays_games AS T1 JOIN Video_games AS T2 ON T1.GameID = T2.GameID WHERE T2.Gname = "Call of Destiny" INTERSECT SELECT T1.StuID FROM Plays_games AS T1 JOIN Video_games AS T2 ON T1.GameID = T2.GameID WHERE T2.Gname = "Works of Widenius")
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 Video_Games ( GameID INTEGER PRIMARY KEY, GName VARCHAR(40), GType VARCHAR(40) ) 3 rows from Video_Games table: GameID GName GType 1 RNG Stone Collectible card game 2 The Vanishing of Eric Calder Walking Simulator 3 Grand Term Assignment Role-playing game CREATE TABLE Plays_Games ( StuID INTEGER, GameID INTEGER, Hours_Played INTEGER, FOREIGN KEY(GameID) REFERENCES Video_Games(GameID), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from Plays_Games table: StuID GameID Hours_Played 1001 1 35 1001 2 15 1001 5 1 CREATE TABLE SportsInfo ( StuID INTEGER, SportName VARCHAR(32), HoursPerWeek INTEGER, GamesPlayed INTEGER, OnScholarship VARCHAR(1), FOREIGN KEY(StuID) REFERENCES Student(StuID) ) 3 rows from SportsInfo table: StuID SportName HoursPerWeek GamesPlayed OnScholarship 1001 Athletics 2 5 N 1002 Football 7 20 Y 1003 Football 45 18 Y
customers_and_addresses
Find the name of all customers.
SELECT customer_name FROM customers
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
What are the names of all the customers?
SELECT customer_name FROM customers
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
How many customers are there?
SELECT count(*) FROM customers
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Return the total number of distinct customers.
SELECT count(*) FROM customers
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
What is the average amount of items ordered in each order?
SELECT avg(order_quantity) FROM order_items
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Find the average order quantity per order.
SELECT avg(order_quantity) FROM order_items
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
What are the names of customers who use payment method "Cash"?
SELECT customer_name FROM customers WHERE payment_method = "Cash"
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Which customers use "Cash" for payment method? Return the customer names.
SELECT customer_name FROM customers WHERE payment_method = "Cash"
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Find the "date became customers" of the customers whose ID is between 10 and 20.
SELECT date_became_customer FROM customers WHERE customer_id BETWEEN 10 AND 20
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
What are the dates when customers with ids between 10 and 20 became customers?
SELECT date_became_customer FROM customers WHERE customer_id BETWEEN 10 AND 20
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Which payment method is used by most customers?
SELECT payment_method FROM customers GROUP BY payment_method ORDER BY count(*) DESC LIMIT 1
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
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 `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
What are the names of customers using the most popular payment method?
SELECT customer_name FROM customers WHERE payment_method = (SELECT payment_method FROM customers GROUP BY payment_method ORDER BY count(*) DESC LIMIT 1)
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Find the name of the customers who use the most frequently used payment method.
SELECT customer_name FROM customers WHERE payment_method = (SELECT payment_method FROM customers GROUP BY payment_method ORDER BY count(*) DESC LIMIT 1)
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
What are all the payment methods?
SELECT DISTINCT payment_method FROM customers
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Return all the distinct payment methods used by customers.
SELECT DISTINCT payment_method FROM customers
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
What are the details of all products?
SELECT DISTINCT product_details FROM products
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Return the the details of all products.
SELECT DISTINCT product_details FROM products
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Find the name of all customers whose name contains "Alex".
SELECT customer_name FROM customers WHERE customer_name LIKE "%Alex%"
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Which customer's name contains "Alex"? Find the full name.
SELECT customer_name FROM customers WHERE customer_name LIKE "%Alex%"
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Find the detail of products whose detail contains the word "Latte" or the word "Americano"
SELECT product_details FROM products WHERE product_details LIKE "%Latte%" OR product_details LIKE "%Americano%"
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Which product's detail contains the word "Latte" or "Americano"? Return the full detail.
SELECT product_details FROM products WHERE product_details LIKE "%Latte%" OR product_details LIKE "%Americano%"
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
What is the address content of the customer named "Maudie Kertzmann"?
SELECT t3.address_content 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 t1.customer_name = "Maudie Kertzmann"
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Return the address content for the customer whose name is "Maudie Kertzmann".
SELECT t3.address_content 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 t1.customer_name = "Maudie Kertzmann"
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
How many customers are living in city "Lake Geovannyton"?
SELECT count(*) 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.city = "Lake Geovannyton"
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Find the number of customers who live in the city called Lake Geovannyton.
SELECT count(*) 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.city = "Lake Geovannyton"
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Find the name of customers who are living in Colorado?
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 = "Colorado"
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
What are the names of customers who live in Colorado state?
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 = "Colorado"
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Find the list of cities that no customer is living in.
SELECT city FROM addresses WHERE city NOT IN ( SELECT DISTINCT t3.city 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)
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
What are the cities no customers live in?
SELECT city FROM addresses WHERE city NOT IN ( SELECT DISTINCT t3.city 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)
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Which city has the most customers living in?
SELECT t3.city 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 GROUP BY t3.city ORDER BY count(*) DESC LIMIT 1
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Find the city where the most customers live.
SELECT t3.city 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 GROUP BY t3.city ORDER BY count(*) DESC LIMIT 1
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Retrieve the list of all cities.
SELECT DISTINCT city FROM addresses
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
List all the distinct cities
SELECT DISTINCT city FROM addresses
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Find the city with post code 255.
SELECT city FROM addresses WHERE zip_postcode = 255
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Which city is post code 255 located in?
SELECT city FROM addresses WHERE zip_postcode = 255
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Find the state and country of all cities with post code starting with 4.
SELECT state_province_county , country FROM addresses WHERE zip_postcode LIKE "4%"
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
What are the state and country of all the cities that have post codes starting with 4.\
SELECT state_province_county , country FROM addresses WHERE zip_postcode LIKE "4%"
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
List the countries having more than 4 addresses listed.
SELECT country FROM addresses GROUP BY country HAVING count(address_id) > 4
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
For which countries are there more than four distinct addresses listed?
SELECT country FROM addresses GROUP BY country HAVING count(address_id) > 4
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
List all the contact channel codes that were used less than 5 times.
SELECT channel_code FROM customer_contact_channels GROUP BY channel_code HAVING count(customer_id) < 5
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Which contact channel codes were used less than 5 times?
SELECT channel_code FROM customer_contact_channels GROUP BY channel_code HAVING count(customer_id) < 5
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Which contact channel has been used by the customer with name "Tillman Ernser"?
SELECT DISTINCT channel_code FROM customers AS t1 JOIN customer_contact_channels AS t2 ON t1.customer_id = t2.customer_id WHERE t1.customer_name = "Tillman Ernser"
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
Find the contact channel code that was used by the customer named "Tillman Ernser".
SELECT DISTINCT channel_code FROM customers AS t1 JOIN customer_contact_channels AS t2 ON t1.customer_id = t2.customer_id WHERE t1.customer_name = "Tillman Ernser"
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2
customers_and_addresses
What is the "active to date" of the latest contact channel used by "Tillman Ernser"?
SELECT max(t2.active_to_date) FROM customers AS t1 JOIN customer_contact_channels AS t2 ON t1.customer_id = t2.customer_id WHERE t1.customer_name = "Tillman Ernser"
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `address_content` VARCHAR(80), `city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ) 3 rows from Addresses table: address_id address_content city zip_postcode state_province_county country other_address_details 1 9443 Boyle Route Suite 857 Lucasville 416 Colorado USA None 2 1969 Jabari Port Suite 393 New Sabryna 721 SouthCarolina USA None 3 295 Hackett Curve Reingertown 255 NewJersey USA None CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_details` VARCHAR(255) ) 3 rows from Products table: product_id product_details 1 Americano 2 Dove Chocolate 3 Latte CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `date_became_customer` DATETIME, `other_customer_details` VARCHAR(255) ) 3 rows from Customers table: customer_id payment_method customer_name date_became_customer other_customer_details 1 Cash Dr. Julia Wuckert MD 2018-03-01 23:20:10 None 2 Cheque Tillman Ernser 2018-02-28 11:37:44 None 3 Credit Card Rodrick Heaney 2018-03-09 17:41:58 None CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Addresses table: customer_id address_id date_address_from address_type date_address_to 2 11 1985-03-29 20:31:43 Billing 1993-02-17 17:55:18 13 11 2010-08-25 04:24:35 Billing 1972-02-17 22:23:38 2 14 2010-12-26 08:52:50 Residential 1979-07-16 18:22:39 CREATE TABLE `Customer_Contact_Channels` ( `customer_id` INTEGER NOT NULL, `channel_code` VARCHAR(15) NOT NULL, `active_from_date` DATETIME NOT NULL, `active_to_date` DATETIME, `contact_number` VARCHAR(50) NOT NULL, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Contact_Channels table: customer_id channel_code active_from_date active_to_date contact_number 9 Email 2017-12-07 18:18:15 2018-03-23 13:37:14 940.035.6435x0225 2 Email 2017-04-07 04:51:41 2018-03-23 01:30:52 189.449.8326x7607 9 Email 2017-05-25 16:08:45 2018-03-13 07:32:25 958-653-2640 CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status` VARCHAR(15) NOT NULL, `order_date` DATETIME, `order_details` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ) 3 rows from Customer_Orders table: order_id customer_id order_status order_date order_details 1 15 Cancelled 2018-03-21 11:20:46 None 2 3 Cancelled 2018-03-05 06:35:33 None 3 5 Delivered 2018-03-04 07:16:22 Second time CREATE TABLE `Order_Items` ( `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `order_quantity` VARCHAR(15), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) ) 3 rows from Order_Items table: order_id product_id order_quantity 14 2 5 5 2 9 14 3 2