db_id
stringclasses 127
values | query
stringlengths 20
523
| question
stringlengths 16
224
| schema
stringclasses 127
values |
---|---|---|---|
game_1 | SELECT sportname FROM Sportsinfo WHERE onscholarship = 'Y' GROUP BY sportname ORDER BY count(*) DESC LIMIT 1 | What is the sport with the most scholarship students? | 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT StuID FROM Student EXCEPT SELECT StuID FROM Sportsinfo | Show student ids who don't have any sports. | 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT StuID FROM Student EXCEPT SELECT StuID FROM Sportsinfo | What are the ids of all students who don't play sports? | 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT StuID FROM Student WHERE major = 600 INTERSECT SELECT StuID FROM Sportsinfo WHERE onscholarship = 'Y' | Show student ids who are on scholarship and have major 600. | create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT StuID FROM Student WHERE major = 600 INTERSECT SELECT StuID FROM Sportsinfo WHERE onscholarship = 'Y' | What are the student ids for those on scholarship in major number 600? | create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT StuID FROM Student WHERE sex = 'F' INTERSECT SELECT StuID FROM Sportsinfo WHERE sportname = "Football" | Show student ids who are female and play 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT StuID FROM Student WHERE sex = 'F' INTERSECT SELECT StuID FROM Sportsinfo WHERE sportname = "Football" | What are the ids of all female students who play 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT StuID FROM Student WHERE sex = 'M' EXCEPT SELECT StuID FROM Sportsinfo WHERE sportname = "Football" | Show all male student ids who don't play 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT StuID FROM Student WHERE sex = 'M' EXCEPT SELECT StuID FROM Sportsinfo WHERE sportname = "Football" | What are the ids of all male students who do not play 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | 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" | Show total hours per week and number of games played for student David 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | 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" | What is the total number of hours per work and number of games played by David 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT sum(hoursperweek) , sum(gamesplayed) FROM Sportsinfo AS T1 JOIN Student AS T2 ON T1.StuID = T2.StuID WHERE T2.age < 20 | Show total hours per week and number of games played for students under 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT sum(hoursperweek) , sum(gamesplayed) FROM Sportsinfo AS T1 JOIN Student AS T2 ON T1.StuID = T2.StuID WHERE T2.age < 20 | What is the total number of hours per week and number of games played by students under 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT count(DISTINCT StuID) FROM Plays_games | How many students play video 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT count(DISTINCT StuID) FROM Plays_games | How many different students play 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT StuID FROM Student EXCEPT SELECT StuID FROM Plays_games | Show ids of students who don't play video game. | 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT StuID FROM Student EXCEPT SELECT StuID FROM Plays_games | What are the ids of all students who are not video game players? | 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT StuID FROM Sportsinfo INTERSECT SELECT StuID FROM Plays_games | Show ids of students who play video game and play sports. | 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT StuID FROM Sportsinfo INTERSECT SELECT StuID FROM Plays_games | What are the ids of all students who played video games and sports? | 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT gameid , sum(hours_played) FROM Plays_games GROUP BY gameid | Show all game ids and the number of hours played. | 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT gameid , sum(hours_played) FROM Plays_games GROUP BY gameid | What are ids and total number of hours played for each game? | 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT Stuid , sum(hours_played) FROM Plays_games GROUP BY Stuid | Show all student ids and the number of hours played. | 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT Stuid , sum(hours_played) FROM Plays_games GROUP BY Stuid | What are the ids of all students and number of hours played? | 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | 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 | Show the game name that has most number of hours played. | 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | 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 | What is the name of the game that has been played the most? | 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | 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 | Show all game names played by at least 1000 hours. | 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | 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 | What are the names of all the games that have been played for at least 1000 hours? | 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | 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" | Show all game names played by Linda Smith | create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | 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" | What are the names of all games played by Linda Smith? | create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | 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" | Find the last and first name of students who are playing Football or 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | 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" | What is the first and last name of all students who play Football or 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT fname , age FROM Student WHERE StuID IN (SELECT StuID FROM Sportsinfo WHERE SportName = "Football" INTERSECT SELECT StuID FROM Sportsinfo WHERE SportName = "Lacrosse") | Find the first name and age of the students who are playing both Football and 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | SELECT fname , age FROM Student WHERE StuID IN (SELECT StuID FROM Sportsinfo WHERE SportName = "Football" INTERSECT SELECT StuID FROM Sportsinfo WHERE SportName = "Lacrosse") | What are the first names and ages of all students who are playing both Football and 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | 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") | Find the last name and gender of the students who are playing both Call of Destiny and Works of Widenius 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
game_1 | 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") | what is the last name and gender of all students who played both Call of Destiny and 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)
);
create table Video_Games (
GameID INTEGER PRIMARY KEY,
GName VARCHAR(40),
GType VARCHAR(40)
);
create table Plays_Games (
StuID INTEGER,
GameID INTEGER,
Hours_Played INTEGER,
FOREIGN KEY(GameID) REFERENCES Video_Games(GameID),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
create table SportsInfo (
StuID INTEGER,
SportName VARCHAR(32),
HoursPerWeek INTEGER,
GamesPlayed INTEGER,
OnScholarship VARCHAR(1),
FOREIGN KEY(StuID) REFERENCES Student(StuID)
);
INSERT into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
INSERT into Video_Games values ( 1, 'RNG Stone', 'Collectible card game');
INSERT into Plays_Games values ( 1001, 1, 35);
INSERT INTO SportsInfo VALUES (1001, "Athletics", 2, 5, "N"); |
customers_and_addresses | SELECT customer_name FROM customers | Find the name of all 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT customer_name FROM customers | What are the names of all the 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT count(*) FROM customers | How many customers are there? | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT count(*) FROM customers | Return the total number of distinct 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT avg(order_quantity) FROM order_items | What is the average amount of items ordered in each order? | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT avg(order_quantity) FROM order_items | Find the average order quantity per order. | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT customer_name FROM customers WHERE payment_method = "Cash" | What are the names of customers who use 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT customer_name FROM customers WHERE payment_method = "Cash" | Which customers use "Cash" for payment method? Return the customer names. | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT date_became_customer FROM customers WHERE customer_id BETWEEN 10 AND 20 | Find the "date became customers" of the customers whose ID is 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT date_became_customer FROM customers WHERE customer_id BETWEEN 10 AND 20 | What are the dates when customers with ids between 10 and 20 became 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT payment_method FROM customers GROUP BY payment_method ORDER BY count(*) DESC LIMIT 1 | Which payment method is used by most 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT payment_method FROM customers GROUP BY payment_method ORDER BY count(*) DESC LIMIT 1 | Find the payment method that is used most frequently. | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT customer_name FROM customers WHERE payment_method = (SELECT payment_method FROM customers GROUP BY payment_method ORDER BY count(*) DESC LIMIT 1) | What are the names of customers using the most popular payment method? | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT customer_name FROM customers WHERE payment_method = (SELECT payment_method FROM customers GROUP BY payment_method ORDER BY count(*) DESC LIMIT 1) | Find the name of the customers who use the most frequently used payment method. | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT DISTINCT payment_method FROM customers | What are all the payment methods? | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT DISTINCT payment_method FROM customers | Return all the distinct payment methods used by 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT DISTINCT product_details FROM products | What are the details of all 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT DISTINCT product_details FROM products | Return the the details of all 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT customer_name FROM customers WHERE customer_name LIKE "%Alex%" | Find the name of all customers whose name contains "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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT customer_name FROM customers WHERE customer_name LIKE "%Alex%" | Which customer's name contains "Alex"? Find the full name. | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT product_details FROM products WHERE product_details LIKE "%Latte%" OR product_details LIKE "%Americano%" | Find the detail of products whose detail contains the word "Latte" or the word "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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT product_details FROM products WHERE product_details LIKE "%Latte%" OR product_details LIKE "%Americano%" | Which product's detail contains the word "Latte" or "Americano"? Return the full detail. | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | 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" | What is the address content of the customer named "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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | 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" | Return the address content for the customer whose name is "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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | 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" | How many customers are living in 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | 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" | Find the number of customers who live in the city called 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | 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" | Find the name of customers who are living in 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | 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" | What are the names of customers who live in Colorado state? | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | 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) | Find the list of cities that no customer is living in. | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | 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) | What are the cities no customers live in? | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | 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 | Which city has the most customers living in? | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | 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 | Find the city where the most customers live. | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT DISTINCT city FROM addresses | Retrieve the list of all cities. | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT DISTINCT city FROM addresses | List all the distinct cities | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT city FROM addresses WHERE zip_postcode = 255 | Find the city with post code 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT city FROM addresses WHERE zip_postcode = 255 | Which city is post code 255 located in? | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT state_province_county , country FROM addresses WHERE zip_postcode LIKE "4%" | Find the state and country of all cities with post code starting with 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT state_province_county , country FROM addresses WHERE zip_postcode LIKE "4%" | What are the state and country of all the cities that have post codes starting with 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT country FROM addresses GROUP BY country HAVING count(address_id) > 4 | List the countries having more than 4 addresses listed. | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT country FROM addresses GROUP BY country HAVING count(address_id) > 4 | For which countries are there more than four distinct addresses listed? | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT channel_code FROM customer_contact_channels GROUP BY channel_code HAVING count(customer_id) < 5 | List all the contact channel codes that were used less than 5 times. | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT channel_code FROM customer_contact_channels GROUP BY channel_code HAVING count(customer_id) < 5 | Which contact channel codes were used less than 5 times? | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | 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" | Which contact channel has been used by the customer with 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | 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" | Find the contact channel code that was used by the customer named "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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | 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" | What is the "active to date" of the latest contact channel used by "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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | 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" | Return the the "active to date" of the latest contact channel used by the customer named "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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT avg(active_to_date - active_from_date) FROM customer_contact_channels | What is the average time span of contact channels in the database? | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT avg(active_to_date - active_from_date) FROM customer_contact_channels | Compute the average active time span of contact channels. | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT channel_code , contact_number FROM customer_contact_channels WHERE active_to_date - active_from_date = (SELECT active_to_date - active_from_date FROM customer_contact_channels ORDER BY (active_to_date - active_from_date) DESC LIMIT 1) | What is the channel code and contact number of the customer contact channel that was active for the longest time? | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT channel_code , contact_number FROM customer_contact_channels WHERE active_to_date - active_from_date = (SELECT active_to_date - active_from_date FROM customer_contact_channels ORDER BY (active_to_date - active_from_date) DESC LIMIT 1) | Return the channel code and contact number of the customer contact channel whose active duration was the longest. | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT t1.customer_name , t2.active_from_date FROM customers AS t1 JOIN customer_contact_channels AS t2 ON t1.customer_id = t2.customer_id WHERE t2.channel_code = 'Email' | Find the name and active date of the customer that use email as the contact channel. | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT t1.customer_name , t2.active_from_date FROM customers AS t1 JOIN customer_contact_channels AS t2 ON t1.customer_id = t2.customer_id WHERE t2.channel_code = 'Email' | What are the name and active date of the customers whose contact channel code is email? | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT t1.customer_name FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id JOIN order_items AS t3 ON t2.order_id = t3.order_id WHERE t3.order_quantity = ( SELECT max(order_quantity) FROM order_items) | What is the name of the customer that made the order with the largest quantity? | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT t1.customer_name FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id JOIN order_items AS t3 ON t2.order_id = t3.order_id WHERE t3.order_quantity = ( SELECT max(order_quantity) FROM order_items) | Find the name of the customer who made the order of the largest amount of goods. | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT t1.customer_name FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id JOIN order_items AS t3 ON t2.order_id = t3.order_id GROUP BY t1.customer_name ORDER BY sum(t3.order_quantity) DESC LIMIT 1 | What is the name of the customer that has purchased the most 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT t1.customer_name FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id JOIN order_items AS t3 ON t2.order_id = t3.order_id GROUP BY t1.customer_name ORDER BY sum(t3.order_quantity) DESC LIMIT 1 | Give me the name of the customer who ordered the most items in total. | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT t1.payment_method FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id JOIN order_items AS t3 ON t2.order_id = t3.order_id GROUP BY t1.customer_name ORDER BY sum(t3.order_quantity) LIMIT 1 | What is the payment method of the customer that has purchased the least quantity of 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT t1.payment_method FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id JOIN order_items AS t3 ON t2.order_id = t3.order_id GROUP BY t1.customer_name ORDER BY sum(t3.order_quantity) LIMIT 1 | Tell me the payment method used by the customer who ordered the least amount of goods in total. | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT count(DISTINCT t3.product_id) FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id JOIN order_items AS t3 ON t2.order_id = t3.order_id WHERE t1.customer_name = "Rodrick Heaney" | How many types of products have Rodrick Heaney bought in total? | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT count(DISTINCT t3.product_id) FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id JOIN order_items AS t3 ON t2.order_id = t3.order_id WHERE t1.customer_name = "Rodrick Heaney" | Find the number of distinct products Rodrick Heaney has bought so far. | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT sum(t3.order_quantity) FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id JOIN order_items AS t3 ON t2.order_id = t3.order_id WHERE t1.customer_name = "Rodrick Heaney" | What is the total quantity of products purchased by "Rodrick Heaney"? | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT sum(t3.order_quantity) FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id JOIN order_items AS t3 ON t2.order_id = t3.order_id WHERE t1.customer_name = "Rodrick Heaney" | Tell me the total quantity of products bought by the customer called "Rodrick Heaney". | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT count(DISTINCT customer_id) FROM customer_orders WHERE order_status = "Cancelled" | How many customers have at least one order with status "Cancelled"? | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT count(DISTINCT customer_id) FROM customer_orders WHERE order_status = "Cancelled" | Return the number of customers who have at least one order with "Cancelled" status. | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |
customers_and_addresses | SELECT count(*) FROM customer_orders WHERE order_details = "Second time" | How many orders have detail "Second time"? | 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)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_details` VARCHAR(255)
);
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)
);
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` )
);
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` )
);
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` )
);
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` )
);
INSERT INTO Addresses (`address_id`, `address_content`, `city`, `zip_postcode`, `state_province_county`, `country`, `other_address_details`) VALUES (1, '9443 Boyle Route Suite 857', 'Lucasville', '416', 'Colorado', 'USA', NULL)
INSERT INTO Products (`product_id`, `product_details`) VALUES (1, 'Americano')
INSERT INTO Customers (`customer_id`, `payment_method`, `customer_name`, `date_became_customer`, `other_customer_details`) VALUES (1, 'Cash', 'Dr. Julia Wuckert MD', '2018-03-01 23:20:10', NULL)
INSERT INTO Customer_Addresses (`customer_id`, `address_id`, `date_address_from`, `address_type`, `date_address_to`) VALUES (2, 11, '1985-03-29 20:31:43', 'Billing', '1993-02-17 17:55:18')
INSERT INTO Customer_Contact_Channels (`customer_id`, `channel_code`, `active_from_date`, `active_to_date`, `contact_number`) VALUES (9, 'Email', '2017-12-07 18:18:15', '2018-03-23 13:37:14', '940.035.6435x0225')
INSERT INTO Customer_Orders (`order_id`, `customer_id`, `order_status`, `order_date`, `order_details`) VALUES (1, 15, 'Cancelled', '2018-03-21 11:20:46', NULL)
INSERT INTO Order_Items (`order_id`, `product_id`, `order_quantity`) VALUES (14, 2, '5') |