db_id stringclasses 146
values | question stringlengths 3 224 | sql stringlengths 18 577 | database_schema stringclasses 146
values |
|---|---|---|---|
college_3 | What is the average gradepoint for students with the last name Smith? | SELECT avg(T2.gradepoint) FROM ENROLLED_IN AS T1 JOIN GRADECONVERSION AS T2 JOIN STUDENT AS T3 ON T1.Grade = T2.lettergrade AND T1.StuID = T3.StuID WHERE T3.LName = "Smith" | CREATE TABLE Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
)
3 rows from Student table:
StuID LName Fname Age Sex Major Advisor city_code
1001 Smith Linda 18 F 600 1121 BAL
1002 Kim Tracy 19 F 600 7712 HKG
1003 Jones Shiela 21 F 600 7792 WAS
CREATE TABLE Faculty (
FacID INTEGER PRIMARY KEY,
Lname VARCHAR(15),
Fname VARCHAR(15),
Rank VARCHAR(15),
Sex VARCHAR(1),
Phone INTEGER,
Room VARCHAR(5),
Building VARCHAR(13)
)
3 rows from Faculty table:
FacID Lname Fname Rank Sex Phone Room Building
1082 Giuliano Mark Instructor M 2424 224 NEB
1121 Goodrich Michael Professor M 3593 219 NEB
1148 Masson Gerald Professor M 3402 224B NEB
CREATE TABLE Department (
DNO INTEGER PRIMARY KEY,
Division VARCHAR(2),
DName VARCHAR(25),
Room VARCHAR(5),
Building VARCHAR(13),
DPhone INTEGER
)
3 rows from Department table:
DNO Division DName Room Building DPhone
10 AS History of Art 268 Mergenthaler 7117
20 AS Biology 144 Mudd 7330
30 AS Chemistry 113 Remsen 7429
CREATE TABLE Member_of (
FacID INTEGER,
DNO INTEGER,
Appt_Type VARCHAR(15),
FOREIGN KEY(FacID) REFERENCES Faculty(FacID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Member_of table:
FacID DNO Appt_Type
7792 600 Primary
9210 520 Primary
9811 550 Primary
CREATE TABLE Course (
CID VARCHAR(7) PRIMARY KEY,
CName VARCHAR(40),
Credits INTEGER,
Instructor INTEGER,
Days VARCHAR(5),
Hours VARCHAR(11),
DNO INTEGER,
FOREIGN KEY(Instructor) REFERENCES Faculty(FacID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Course table:
CID CName Credits Instructor Days Hours DNO
600.101 COMPUTER LITERACY 3 6112 MTW 3 600
600.103 INTRODUCTION TO COMPUTER SCIENCE 1 4230 Th 4 600
600.107 INTRO TO PROGRAMMING IN JAVA 3 1193 MTW 3 600
CREATE TABLE Minor_in (
StuID INTEGER,
DNO INTEGER,
FOREIGN KEY(StuID) REFERENCES Student(StuID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Minor_in table:
StuID DNO
1004 520
1005 550
1006 50
CREATE TABLE Enrolled_in (
StuID INTEGER,
CID VARCHAR(7),
Grade VARCHAR(2),
FOREIGN KEY(StuID) REFERENCES Student(StuID),
FOREIGN KEY(CID) REFERENCES Course(CID),
FOREIGN KEY(Grade) REFERENCES Gradeconversion(lettergrade)
)
3 rows from Enrolled_in table:
StuID CID Grade
1001 550.681 A-
1001 600.303 B
1001 600.315 B+
CREATE TABLE Gradeconversion (
lettergrade VARCHAR(2) PRIMARY KEY,
gradepoint FLOAT
)
3 rows from Gradeconversion table:
lettergrade gradepoint
A+ 4.0
A 4.0
A- 3.7
|
college_3 | What is the maximum and minimum grade point of students who live in NYC? | SELECT max(T2.gradepoint) , min(T2.gradepoint) FROM ENROLLED_IN AS T1 JOIN GRADECONVERSION AS T2 JOIN STUDENT AS T3 ON T1.Grade = T2.lettergrade AND T1.StuID = T3.StuID WHERE T3.city_code = "NYC" | CREATE TABLE Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
)
3 rows from Student table:
StuID LName Fname Age Sex Major Advisor city_code
1001 Smith Linda 18 F 600 1121 BAL
1002 Kim Tracy 19 F 600 7712 HKG
1003 Jones Shiela 21 F 600 7792 WAS
CREATE TABLE Faculty (
FacID INTEGER PRIMARY KEY,
Lname VARCHAR(15),
Fname VARCHAR(15),
Rank VARCHAR(15),
Sex VARCHAR(1),
Phone INTEGER,
Room VARCHAR(5),
Building VARCHAR(13)
)
3 rows from Faculty table:
FacID Lname Fname Rank Sex Phone Room Building
1082 Giuliano Mark Instructor M 2424 224 NEB
1121 Goodrich Michael Professor M 3593 219 NEB
1148 Masson Gerald Professor M 3402 224B NEB
CREATE TABLE Department (
DNO INTEGER PRIMARY KEY,
Division VARCHAR(2),
DName VARCHAR(25),
Room VARCHAR(5),
Building VARCHAR(13),
DPhone INTEGER
)
3 rows from Department table:
DNO Division DName Room Building DPhone
10 AS History of Art 268 Mergenthaler 7117
20 AS Biology 144 Mudd 7330
30 AS Chemistry 113 Remsen 7429
CREATE TABLE Member_of (
FacID INTEGER,
DNO INTEGER,
Appt_Type VARCHAR(15),
FOREIGN KEY(FacID) REFERENCES Faculty(FacID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Member_of table:
FacID DNO Appt_Type
7792 600 Primary
9210 520 Primary
9811 550 Primary
CREATE TABLE Course (
CID VARCHAR(7) PRIMARY KEY,
CName VARCHAR(40),
Credits INTEGER,
Instructor INTEGER,
Days VARCHAR(5),
Hours VARCHAR(11),
DNO INTEGER,
FOREIGN KEY(Instructor) REFERENCES Faculty(FacID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Course table:
CID CName Credits Instructor Days Hours DNO
600.101 COMPUTER LITERACY 3 6112 MTW 3 600
600.103 INTRODUCTION TO COMPUTER SCIENCE 1 4230 Th 4 600
600.107 INTRO TO PROGRAMMING IN JAVA 3 1193 MTW 3 600
CREATE TABLE Minor_in (
StuID INTEGER,
DNO INTEGER,
FOREIGN KEY(StuID) REFERENCES Student(StuID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Minor_in table:
StuID DNO
1004 520
1005 550
1006 50
CREATE TABLE Enrolled_in (
StuID INTEGER,
CID VARCHAR(7),
Grade VARCHAR(2),
FOREIGN KEY(StuID) REFERENCES Student(StuID),
FOREIGN KEY(CID) REFERENCES Course(CID),
FOREIGN KEY(Grade) REFERENCES Gradeconversion(lettergrade)
)
3 rows from Enrolled_in table:
StuID CID Grade
1001 550.681 A-
1001 600.303 B
1001 600.315 B+
CREATE TABLE Gradeconversion (
lettergrade VARCHAR(2) PRIMARY KEY,
gradepoint FLOAT
)
3 rows from Gradeconversion table:
lettergrade gradepoint
A+ 4.0
A 4.0
A- 3.7
|
college_3 | Give the maximum and minimum gradepoints for students living in NYC? | SELECT max(T2.gradepoint) , min(T2.gradepoint) FROM ENROLLED_IN AS T1 JOIN GRADECONVERSION AS T2 JOIN STUDENT AS T3 ON T1.Grade = T2.lettergrade AND T1.StuID = T3.StuID WHERE T3.city_code = "NYC" | CREATE TABLE Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
)
3 rows from Student table:
StuID LName Fname Age Sex Major Advisor city_code
1001 Smith Linda 18 F 600 1121 BAL
1002 Kim Tracy 19 F 600 7712 HKG
1003 Jones Shiela 21 F 600 7792 WAS
CREATE TABLE Faculty (
FacID INTEGER PRIMARY KEY,
Lname VARCHAR(15),
Fname VARCHAR(15),
Rank VARCHAR(15),
Sex VARCHAR(1),
Phone INTEGER,
Room VARCHAR(5),
Building VARCHAR(13)
)
3 rows from Faculty table:
FacID Lname Fname Rank Sex Phone Room Building
1082 Giuliano Mark Instructor M 2424 224 NEB
1121 Goodrich Michael Professor M 3593 219 NEB
1148 Masson Gerald Professor M 3402 224B NEB
CREATE TABLE Department (
DNO INTEGER PRIMARY KEY,
Division VARCHAR(2),
DName VARCHAR(25),
Room VARCHAR(5),
Building VARCHAR(13),
DPhone INTEGER
)
3 rows from Department table:
DNO Division DName Room Building DPhone
10 AS History of Art 268 Mergenthaler 7117
20 AS Biology 144 Mudd 7330
30 AS Chemistry 113 Remsen 7429
CREATE TABLE Member_of (
FacID INTEGER,
DNO INTEGER,
Appt_Type VARCHAR(15),
FOREIGN KEY(FacID) REFERENCES Faculty(FacID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Member_of table:
FacID DNO Appt_Type
7792 600 Primary
9210 520 Primary
9811 550 Primary
CREATE TABLE Course (
CID VARCHAR(7) PRIMARY KEY,
CName VARCHAR(40),
Credits INTEGER,
Instructor INTEGER,
Days VARCHAR(5),
Hours VARCHAR(11),
DNO INTEGER,
FOREIGN KEY(Instructor) REFERENCES Faculty(FacID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Course table:
CID CName Credits Instructor Days Hours DNO
600.101 COMPUTER LITERACY 3 6112 MTW 3 600
600.103 INTRODUCTION TO COMPUTER SCIENCE 1 4230 Th 4 600
600.107 INTRO TO PROGRAMMING IN JAVA 3 1193 MTW 3 600
CREATE TABLE Minor_in (
StuID INTEGER,
DNO INTEGER,
FOREIGN KEY(StuID) REFERENCES Student(StuID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Minor_in table:
StuID DNO
1004 520
1005 550
1006 50
CREATE TABLE Enrolled_in (
StuID INTEGER,
CID VARCHAR(7),
Grade VARCHAR(2),
FOREIGN KEY(StuID) REFERENCES Student(StuID),
FOREIGN KEY(CID) REFERENCES Course(CID),
FOREIGN KEY(Grade) REFERENCES Gradeconversion(lettergrade)
)
3 rows from Enrolled_in table:
StuID CID Grade
1001 550.681 A-
1001 600.303 B
1001 600.315 B+
CREATE TABLE Gradeconversion (
lettergrade VARCHAR(2) PRIMARY KEY,
gradepoint FLOAT
)
3 rows from Gradeconversion table:
lettergrade gradepoint
A+ 4.0
A 4.0
A- 3.7
|
college_3 | Find the names of courses that have either 3 credits or 1 credit but 4 hours. | SELECT CName FROM COURSE WHERE Credits = 3 UNION SELECT CName FROM COURSE WHERE Credits = 1 AND Hours = 4 | CREATE TABLE Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
)
3 rows from Student table:
StuID LName Fname Age Sex Major Advisor city_code
1001 Smith Linda 18 F 600 1121 BAL
1002 Kim Tracy 19 F 600 7712 HKG
1003 Jones Shiela 21 F 600 7792 WAS
CREATE TABLE Faculty (
FacID INTEGER PRIMARY KEY,
Lname VARCHAR(15),
Fname VARCHAR(15),
Rank VARCHAR(15),
Sex VARCHAR(1),
Phone INTEGER,
Room VARCHAR(5),
Building VARCHAR(13)
)
3 rows from Faculty table:
FacID Lname Fname Rank Sex Phone Room Building
1082 Giuliano Mark Instructor M 2424 224 NEB
1121 Goodrich Michael Professor M 3593 219 NEB
1148 Masson Gerald Professor M 3402 224B NEB
CREATE TABLE Department (
DNO INTEGER PRIMARY KEY,
Division VARCHAR(2),
DName VARCHAR(25),
Room VARCHAR(5),
Building VARCHAR(13),
DPhone INTEGER
)
3 rows from Department table:
DNO Division DName Room Building DPhone
10 AS History of Art 268 Mergenthaler 7117
20 AS Biology 144 Mudd 7330
30 AS Chemistry 113 Remsen 7429
CREATE TABLE Member_of (
FacID INTEGER,
DNO INTEGER,
Appt_Type VARCHAR(15),
FOREIGN KEY(FacID) REFERENCES Faculty(FacID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Member_of table:
FacID DNO Appt_Type
7792 600 Primary
9210 520 Primary
9811 550 Primary
CREATE TABLE Course (
CID VARCHAR(7) PRIMARY KEY,
CName VARCHAR(40),
Credits INTEGER,
Instructor INTEGER,
Days VARCHAR(5),
Hours VARCHAR(11),
DNO INTEGER,
FOREIGN KEY(Instructor) REFERENCES Faculty(FacID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Course table:
CID CName Credits Instructor Days Hours DNO
600.101 COMPUTER LITERACY 3 6112 MTW 3 600
600.103 INTRODUCTION TO COMPUTER SCIENCE 1 4230 Th 4 600
600.107 INTRO TO PROGRAMMING IN JAVA 3 1193 MTW 3 600
CREATE TABLE Minor_in (
StuID INTEGER,
DNO INTEGER,
FOREIGN KEY(StuID) REFERENCES Student(StuID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Minor_in table:
StuID DNO
1004 520
1005 550
1006 50
CREATE TABLE Enrolled_in (
StuID INTEGER,
CID VARCHAR(7),
Grade VARCHAR(2),
FOREIGN KEY(StuID) REFERENCES Student(StuID),
FOREIGN KEY(CID) REFERENCES Course(CID),
FOREIGN KEY(Grade) REFERENCES Gradeconversion(lettergrade)
)
3 rows from Enrolled_in table:
StuID CID Grade
1001 550.681 A-
1001 600.303 B
1001 600.315 B+
CREATE TABLE Gradeconversion (
lettergrade VARCHAR(2) PRIMARY KEY,
gradepoint FLOAT
)
3 rows from Gradeconversion table:
lettergrade gradepoint
A+ 4.0
A 4.0
A- 3.7
|
college_3 | What are the names of courses that give either 3 credits, or 1 credit and 4 hours? | SELECT CName FROM COURSE WHERE Credits = 3 UNION SELECT CName FROM COURSE WHERE Credits = 1 AND Hours = 4 | CREATE TABLE Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
)
3 rows from Student table:
StuID LName Fname Age Sex Major Advisor city_code
1001 Smith Linda 18 F 600 1121 BAL
1002 Kim Tracy 19 F 600 7712 HKG
1003 Jones Shiela 21 F 600 7792 WAS
CREATE TABLE Faculty (
FacID INTEGER PRIMARY KEY,
Lname VARCHAR(15),
Fname VARCHAR(15),
Rank VARCHAR(15),
Sex VARCHAR(1),
Phone INTEGER,
Room VARCHAR(5),
Building VARCHAR(13)
)
3 rows from Faculty table:
FacID Lname Fname Rank Sex Phone Room Building
1082 Giuliano Mark Instructor M 2424 224 NEB
1121 Goodrich Michael Professor M 3593 219 NEB
1148 Masson Gerald Professor M 3402 224B NEB
CREATE TABLE Department (
DNO INTEGER PRIMARY KEY,
Division VARCHAR(2),
DName VARCHAR(25),
Room VARCHAR(5),
Building VARCHAR(13),
DPhone INTEGER
)
3 rows from Department table:
DNO Division DName Room Building DPhone
10 AS History of Art 268 Mergenthaler 7117
20 AS Biology 144 Mudd 7330
30 AS Chemistry 113 Remsen 7429
CREATE TABLE Member_of (
FacID INTEGER,
DNO INTEGER,
Appt_Type VARCHAR(15),
FOREIGN KEY(FacID) REFERENCES Faculty(FacID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Member_of table:
FacID DNO Appt_Type
7792 600 Primary
9210 520 Primary
9811 550 Primary
CREATE TABLE Course (
CID VARCHAR(7) PRIMARY KEY,
CName VARCHAR(40),
Credits INTEGER,
Instructor INTEGER,
Days VARCHAR(5),
Hours VARCHAR(11),
DNO INTEGER,
FOREIGN KEY(Instructor) REFERENCES Faculty(FacID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Course table:
CID CName Credits Instructor Days Hours DNO
600.101 COMPUTER LITERACY 3 6112 MTW 3 600
600.103 INTRODUCTION TO COMPUTER SCIENCE 1 4230 Th 4 600
600.107 INTRO TO PROGRAMMING IN JAVA 3 1193 MTW 3 600
CREATE TABLE Minor_in (
StuID INTEGER,
DNO INTEGER,
FOREIGN KEY(StuID) REFERENCES Student(StuID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Minor_in table:
StuID DNO
1004 520
1005 550
1006 50
CREATE TABLE Enrolled_in (
StuID INTEGER,
CID VARCHAR(7),
Grade VARCHAR(2),
FOREIGN KEY(StuID) REFERENCES Student(StuID),
FOREIGN KEY(CID) REFERENCES Course(CID),
FOREIGN KEY(Grade) REFERENCES Gradeconversion(lettergrade)
)
3 rows from Enrolled_in table:
StuID CID Grade
1001 550.681 A-
1001 600.303 B
1001 600.315 B+
CREATE TABLE Gradeconversion (
lettergrade VARCHAR(2) PRIMARY KEY,
gradepoint FLOAT
)
3 rows from Gradeconversion table:
lettergrade gradepoint
A+ 4.0
A 4.0
A- 3.7
|
college_3 | Find the names of departments that are either in division AS or in division EN and in Building NEB. | SELECT DName FROM DEPARTMENT WHERE Division = "AS" UNION SELECT DName FROM DEPARTMENT WHERE Division = "EN" AND Building = "NEB" | CREATE TABLE Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
)
3 rows from Student table:
StuID LName Fname Age Sex Major Advisor city_code
1001 Smith Linda 18 F 600 1121 BAL
1002 Kim Tracy 19 F 600 7712 HKG
1003 Jones Shiela 21 F 600 7792 WAS
CREATE TABLE Faculty (
FacID INTEGER PRIMARY KEY,
Lname VARCHAR(15),
Fname VARCHAR(15),
Rank VARCHAR(15),
Sex VARCHAR(1),
Phone INTEGER,
Room VARCHAR(5),
Building VARCHAR(13)
)
3 rows from Faculty table:
FacID Lname Fname Rank Sex Phone Room Building
1082 Giuliano Mark Instructor M 2424 224 NEB
1121 Goodrich Michael Professor M 3593 219 NEB
1148 Masson Gerald Professor M 3402 224B NEB
CREATE TABLE Department (
DNO INTEGER PRIMARY KEY,
Division VARCHAR(2),
DName VARCHAR(25),
Room VARCHAR(5),
Building VARCHAR(13),
DPhone INTEGER
)
3 rows from Department table:
DNO Division DName Room Building DPhone
10 AS History of Art 268 Mergenthaler 7117
20 AS Biology 144 Mudd 7330
30 AS Chemistry 113 Remsen 7429
CREATE TABLE Member_of (
FacID INTEGER,
DNO INTEGER,
Appt_Type VARCHAR(15),
FOREIGN KEY(FacID) REFERENCES Faculty(FacID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Member_of table:
FacID DNO Appt_Type
7792 600 Primary
9210 520 Primary
9811 550 Primary
CREATE TABLE Course (
CID VARCHAR(7) PRIMARY KEY,
CName VARCHAR(40),
Credits INTEGER,
Instructor INTEGER,
Days VARCHAR(5),
Hours VARCHAR(11),
DNO INTEGER,
FOREIGN KEY(Instructor) REFERENCES Faculty(FacID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Course table:
CID CName Credits Instructor Days Hours DNO
600.101 COMPUTER LITERACY 3 6112 MTW 3 600
600.103 INTRODUCTION TO COMPUTER SCIENCE 1 4230 Th 4 600
600.107 INTRO TO PROGRAMMING IN JAVA 3 1193 MTW 3 600
CREATE TABLE Minor_in (
StuID INTEGER,
DNO INTEGER,
FOREIGN KEY(StuID) REFERENCES Student(StuID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Minor_in table:
StuID DNO
1004 520
1005 550
1006 50
CREATE TABLE Enrolled_in (
StuID INTEGER,
CID VARCHAR(7),
Grade VARCHAR(2),
FOREIGN KEY(StuID) REFERENCES Student(StuID),
FOREIGN KEY(CID) REFERENCES Course(CID),
FOREIGN KEY(Grade) REFERENCES Gradeconversion(lettergrade)
)
3 rows from Enrolled_in table:
StuID CID Grade
1001 550.681 A-
1001 600.303 B
1001 600.315 B+
CREATE TABLE Gradeconversion (
lettergrade VARCHAR(2) PRIMARY KEY,
gradepoint FLOAT
)
3 rows from Gradeconversion table:
lettergrade gradepoint
A+ 4.0
A 4.0
A- 3.7
|
college_3 | What are the names of departments either in division AS, or in division EN and in building NEB? | SELECT DName FROM DEPARTMENT WHERE Division = "AS" UNION SELECT DName FROM DEPARTMENT WHERE Division = "EN" AND Building = "NEB" | CREATE TABLE Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
)
3 rows from Student table:
StuID LName Fname Age Sex Major Advisor city_code
1001 Smith Linda 18 F 600 1121 BAL
1002 Kim Tracy 19 F 600 7712 HKG
1003 Jones Shiela 21 F 600 7792 WAS
CREATE TABLE Faculty (
FacID INTEGER PRIMARY KEY,
Lname VARCHAR(15),
Fname VARCHAR(15),
Rank VARCHAR(15),
Sex VARCHAR(1),
Phone INTEGER,
Room VARCHAR(5),
Building VARCHAR(13)
)
3 rows from Faculty table:
FacID Lname Fname Rank Sex Phone Room Building
1082 Giuliano Mark Instructor M 2424 224 NEB
1121 Goodrich Michael Professor M 3593 219 NEB
1148 Masson Gerald Professor M 3402 224B NEB
CREATE TABLE Department (
DNO INTEGER PRIMARY KEY,
Division VARCHAR(2),
DName VARCHAR(25),
Room VARCHAR(5),
Building VARCHAR(13),
DPhone INTEGER
)
3 rows from Department table:
DNO Division DName Room Building DPhone
10 AS History of Art 268 Mergenthaler 7117
20 AS Biology 144 Mudd 7330
30 AS Chemistry 113 Remsen 7429
CREATE TABLE Member_of (
FacID INTEGER,
DNO INTEGER,
Appt_Type VARCHAR(15),
FOREIGN KEY(FacID) REFERENCES Faculty(FacID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Member_of table:
FacID DNO Appt_Type
7792 600 Primary
9210 520 Primary
9811 550 Primary
CREATE TABLE Course (
CID VARCHAR(7) PRIMARY KEY,
CName VARCHAR(40),
Credits INTEGER,
Instructor INTEGER,
Days VARCHAR(5),
Hours VARCHAR(11),
DNO INTEGER,
FOREIGN KEY(Instructor) REFERENCES Faculty(FacID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Course table:
CID CName Credits Instructor Days Hours DNO
600.101 COMPUTER LITERACY 3 6112 MTW 3 600
600.103 INTRODUCTION TO COMPUTER SCIENCE 1 4230 Th 4 600
600.107 INTRO TO PROGRAMMING IN JAVA 3 1193 MTW 3 600
CREATE TABLE Minor_in (
StuID INTEGER,
DNO INTEGER,
FOREIGN KEY(StuID) REFERENCES Student(StuID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Minor_in table:
StuID DNO
1004 520
1005 550
1006 50
CREATE TABLE Enrolled_in (
StuID INTEGER,
CID VARCHAR(7),
Grade VARCHAR(2),
FOREIGN KEY(StuID) REFERENCES Student(StuID),
FOREIGN KEY(CID) REFERENCES Course(CID),
FOREIGN KEY(Grade) REFERENCES Gradeconversion(lettergrade)
)
3 rows from Enrolled_in table:
StuID CID Grade
1001 550.681 A-
1001 600.303 B
1001 600.315 B+
CREATE TABLE Gradeconversion (
lettergrade VARCHAR(2) PRIMARY KEY,
gradepoint FLOAT
)
3 rows from Gradeconversion table:
lettergrade gradepoint
A+ 4.0
A 4.0
A- 3.7
|
college_3 | Find the first name of students not enrolled in any course. | SELECT Fname FROM STUDENT WHERE StuID NOT IN (SELECT StuID FROM ENROLLED_IN) | CREATE TABLE Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
)
3 rows from Student table:
StuID LName Fname Age Sex Major Advisor city_code
1001 Smith Linda 18 F 600 1121 BAL
1002 Kim Tracy 19 F 600 7712 HKG
1003 Jones Shiela 21 F 600 7792 WAS
CREATE TABLE Faculty (
FacID INTEGER PRIMARY KEY,
Lname VARCHAR(15),
Fname VARCHAR(15),
Rank VARCHAR(15),
Sex VARCHAR(1),
Phone INTEGER,
Room VARCHAR(5),
Building VARCHAR(13)
)
3 rows from Faculty table:
FacID Lname Fname Rank Sex Phone Room Building
1082 Giuliano Mark Instructor M 2424 224 NEB
1121 Goodrich Michael Professor M 3593 219 NEB
1148 Masson Gerald Professor M 3402 224B NEB
CREATE TABLE Department (
DNO INTEGER PRIMARY KEY,
Division VARCHAR(2),
DName VARCHAR(25),
Room VARCHAR(5),
Building VARCHAR(13),
DPhone INTEGER
)
3 rows from Department table:
DNO Division DName Room Building DPhone
10 AS History of Art 268 Mergenthaler 7117
20 AS Biology 144 Mudd 7330
30 AS Chemistry 113 Remsen 7429
CREATE TABLE Member_of (
FacID INTEGER,
DNO INTEGER,
Appt_Type VARCHAR(15),
FOREIGN KEY(FacID) REFERENCES Faculty(FacID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Member_of table:
FacID DNO Appt_Type
7792 600 Primary
9210 520 Primary
9811 550 Primary
CREATE TABLE Course (
CID VARCHAR(7) PRIMARY KEY,
CName VARCHAR(40),
Credits INTEGER,
Instructor INTEGER,
Days VARCHAR(5),
Hours VARCHAR(11),
DNO INTEGER,
FOREIGN KEY(Instructor) REFERENCES Faculty(FacID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Course table:
CID CName Credits Instructor Days Hours DNO
600.101 COMPUTER LITERACY 3 6112 MTW 3 600
600.103 INTRODUCTION TO COMPUTER SCIENCE 1 4230 Th 4 600
600.107 INTRO TO PROGRAMMING IN JAVA 3 1193 MTW 3 600
CREATE TABLE Minor_in (
StuID INTEGER,
DNO INTEGER,
FOREIGN KEY(StuID) REFERENCES Student(StuID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Minor_in table:
StuID DNO
1004 520
1005 550
1006 50
CREATE TABLE Enrolled_in (
StuID INTEGER,
CID VARCHAR(7),
Grade VARCHAR(2),
FOREIGN KEY(StuID) REFERENCES Student(StuID),
FOREIGN KEY(CID) REFERENCES Course(CID),
FOREIGN KEY(Grade) REFERENCES Gradeconversion(lettergrade)
)
3 rows from Enrolled_in table:
StuID CID Grade
1001 550.681 A-
1001 600.303 B
1001 600.315 B+
CREATE TABLE Gradeconversion (
lettergrade VARCHAR(2) PRIMARY KEY,
gradepoint FLOAT
)
3 rows from Gradeconversion table:
lettergrade gradepoint
A+ 4.0
A 4.0
A- 3.7
|
college_3 | What are the first names of all students that are not enrolled in courses? | SELECT Fname FROM STUDENT WHERE StuID NOT IN (SELECT StuID FROM ENROLLED_IN) | CREATE TABLE Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
)
3 rows from Student table:
StuID LName Fname Age Sex Major Advisor city_code
1001 Smith Linda 18 F 600 1121 BAL
1002 Kim Tracy 19 F 600 7712 HKG
1003 Jones Shiela 21 F 600 7792 WAS
CREATE TABLE Faculty (
FacID INTEGER PRIMARY KEY,
Lname VARCHAR(15),
Fname VARCHAR(15),
Rank VARCHAR(15),
Sex VARCHAR(1),
Phone INTEGER,
Room VARCHAR(5),
Building VARCHAR(13)
)
3 rows from Faculty table:
FacID Lname Fname Rank Sex Phone Room Building
1082 Giuliano Mark Instructor M 2424 224 NEB
1121 Goodrich Michael Professor M 3593 219 NEB
1148 Masson Gerald Professor M 3402 224B NEB
CREATE TABLE Department (
DNO INTEGER PRIMARY KEY,
Division VARCHAR(2),
DName VARCHAR(25),
Room VARCHAR(5),
Building VARCHAR(13),
DPhone INTEGER
)
3 rows from Department table:
DNO Division DName Room Building DPhone
10 AS History of Art 268 Mergenthaler 7117
20 AS Biology 144 Mudd 7330
30 AS Chemistry 113 Remsen 7429
CREATE TABLE Member_of (
FacID INTEGER,
DNO INTEGER,
Appt_Type VARCHAR(15),
FOREIGN KEY(FacID) REFERENCES Faculty(FacID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Member_of table:
FacID DNO Appt_Type
7792 600 Primary
9210 520 Primary
9811 550 Primary
CREATE TABLE Course (
CID VARCHAR(7) PRIMARY KEY,
CName VARCHAR(40),
Credits INTEGER,
Instructor INTEGER,
Days VARCHAR(5),
Hours VARCHAR(11),
DNO INTEGER,
FOREIGN KEY(Instructor) REFERENCES Faculty(FacID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Course table:
CID CName Credits Instructor Days Hours DNO
600.101 COMPUTER LITERACY 3 6112 MTW 3 600
600.103 INTRODUCTION TO COMPUTER SCIENCE 1 4230 Th 4 600
600.107 INTRO TO PROGRAMMING IN JAVA 3 1193 MTW 3 600
CREATE TABLE Minor_in (
StuID INTEGER,
DNO INTEGER,
FOREIGN KEY(StuID) REFERENCES Student(StuID),
FOREIGN KEY(DNO) REFERENCES Department(DNO)
)
3 rows from Minor_in table:
StuID DNO
1004 520
1005 550
1006 50
CREATE TABLE Enrolled_in (
StuID INTEGER,
CID VARCHAR(7),
Grade VARCHAR(2),
FOREIGN KEY(StuID) REFERENCES Student(StuID),
FOREIGN KEY(CID) REFERENCES Course(CID),
FOREIGN KEY(Grade) REFERENCES Gradeconversion(lettergrade)
)
3 rows from Enrolled_in table:
StuID CID Grade
1001 550.681 A-
1001 600.303 B
1001 600.315 B+
CREATE TABLE Gradeconversion (
lettergrade VARCHAR(2) PRIMARY KEY,
gradepoint FLOAT
)
3 rows from Gradeconversion table:
lettergrade gradepoint
A+ 4.0
A 4.0
A- 3.7
|
department_store | What are the ids of the top three products that were purchased in the largest amount? | SELECT product_id FROM product_suppliers ORDER BY total_amount_purchased DESC LIMIT 3 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Give the ids of the three products purchased in the largest amounts. | SELECT product_id FROM product_suppliers ORDER BY total_amount_purchased DESC LIMIT 3 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the product id and product type of the cheapest product? | SELECT product_id , product_type_code FROM products ORDER BY product_price LIMIT 1 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Give the id and product type of the product with the lowest price. | SELECT product_id , product_type_code FROM products ORDER BY product_price LIMIT 1 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Find the number of different product types. | SELECT count(DISTINCT product_type_code) FROM products | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Count the number of distinct product types. | SELECT count(DISTINCT product_type_code) FROM products | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Return the address of customer 10. | SELECT T1.address_details FROM addresses AS T1 JOIN customer_addresses AS T2 ON T1.address_id = T2.address_id WHERE T2.customer_id = 10 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What is the address for the customer with id 10? | SELECT T1.address_details FROM addresses AS T1 JOIN customer_addresses AS T2 ON T1.address_id = T2.address_id WHERE T2.customer_id = 10 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the staff ids and genders of all staffs whose job title is Department Manager? | SELECT T1.staff_id , T1.staff_gender FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id = T2.staff_id WHERE T2.job_title_code = "Department Manager" | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Return the staff ids and genders for any staff with the title Department Manager. | SELECT T1.staff_id , T1.staff_gender FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id = T2.staff_id WHERE T2.job_title_code = "Department Manager" | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | For each payment method, return how many customers use it. | SELECT payment_method_code , count(*) FROM customers GROUP BY payment_method_code | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | How many customers use each payment method? | SELECT payment_method_code , count(*) FROM customers GROUP BY payment_method_code | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What is the id of the product that was ordered the most often? | SELECT product_id FROM order_items GROUP BY product_id ORDER BY count(*) DESC LIMIT 1 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Give the product id for the product that was ordered most frequently. | SELECT product_id FROM order_items GROUP BY product_id ORDER BY count(*) DESC LIMIT 1 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the name, phone number and email address of the customer who made the largest number of orders? | SELECT T1.customer_name , T1.customer_phone , T1.customer_email FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id GROUP BY T2.customer_id ORDER BY count(*) DESC LIMIT 1 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Return the name, phone number and email address for the customer with the most orders. | SELECT T1.customer_name , T1.customer_phone , T1.customer_email FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id GROUP BY T2.customer_id ORDER BY count(*) DESC LIMIT 1 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What is the average price for each type of product? | SELECT product_type_code , avg(product_price) FROM products GROUP BY product_type_code | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Return the average price for each product type. | SELECT product_type_code , avg(product_price) FROM products GROUP BY product_type_code | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | How many department stores does the store chain South have? | SELECT count(*) FROM department_stores AS T1 JOIN department_store_chain AS T2 ON T1.dept_store_chain_id = T2.dept_store_chain_id WHERE T2.dept_store_chain_name = "South" | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Count the number of stores the chain South has. | SELECT count(*) FROM department_stores AS T1 JOIN department_store_chain AS T2 ON T1.dept_store_chain_id = T2.dept_store_chain_id WHERE T2.dept_store_chain_name = "South" | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What is the name and job title of the staff who was assigned the latest? | SELECT T1.staff_name , T2.job_title_code FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id = T2.staff_id ORDER BY T2.date_assigned_to DESC LIMIT 1 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Return the name and job title of the staff with the latest date assigned. | SELECT T1.staff_name , T2.job_title_code FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id = T2.staff_id ORDER BY T2.date_assigned_to DESC LIMIT 1 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Give me the product type, name and price for all the products supplied by supplier id 3. | SELECT T2.product_type_code , T2.product_name , T2.product_price FROM product_suppliers AS T1 JOIN products AS T2 ON T1.product_id = T2.product_id WHERE T1.supplier_id = 3 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Return the product type, name, and price for products supplied by supplier 3. | SELECT T2.product_type_code , T2.product_name , T2.product_price FROM product_suppliers AS T1 JOIN products AS T2 ON T1.product_id = T2.product_id WHERE T1.supplier_id = 3 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Return the distinct name of customers whose order status is Pending, in the order of customer id. | SELECT DISTINCT T1.customer_name FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status_code = "Pending" ORDER BY T2.customer_id | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the distinct names of customers with an order status of Pending, sorted by customer id? | SELECT DISTINCT T1.customer_name FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status_code = "Pending" ORDER BY T2.customer_id | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Find the name and address of the customers who have both New and Pending orders. | SELECT T1.customer_name , T1.customer_address FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status_code = "New" INTERSECT SELECT T1.customer_name , T1.customer_address FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status_code = "Pending" | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the names and addressed of customers who have both New and Pending orders? | SELECT T1.customer_name , T1.customer_address FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status_code = "New" INTERSECT SELECT T1.customer_name , T1.customer_address FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status_code = "Pending" | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Return ids of all the products that are supplied by supplier id 2 and are more expensive than the average price of all products. | SELECT T1.product_id FROM product_suppliers AS T1 JOIN products AS T2 ON T1.product_id = T2.product_id WHERE T1.supplier_id = 2 AND T2.product_price > (SELECT avg(product_price) FROM products) | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the ids of products from the supplier with id 2, which are more expensive than the average price across all products? | SELECT T1.product_id FROM product_suppliers AS T1 JOIN products AS T2 ON T1.product_id = T2.product_id WHERE T1.supplier_id = 2 AND T2.product_price > (SELECT avg(product_price) FROM products) | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What is the id and name of the department store that has both marketing and managing department? | SELECT T2.dept_store_id , T2.store_name FROM departments AS T1 JOIN department_stores AS T2 ON T1.dept_store_id = T2.dept_store_id WHERE T1.department_name = "marketing" INTERSECT SELECT T2.dept_store_id , T2.store_name FROM departments AS T1 JOIN department_stores AS T2 ON T1.dept_store_id = T2.dept_store_id WHERE T1.department_name = "managing" | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the ids and names of department stores with both marketing and managing departments? | SELECT T2.dept_store_id , T2.store_name FROM departments AS T1 JOIN department_stores AS T2 ON T1.dept_store_id = T2.dept_store_id WHERE T1.department_name = "marketing" INTERSECT SELECT T2.dept_store_id , T2.store_name FROM departments AS T1 JOIN department_stores AS T2 ON T1.dept_store_id = T2.dept_store_id WHERE T1.department_name = "managing" | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the ids of the two department store chains with the largest number of department stores? | SELECT dept_store_chain_id FROM department_stores GROUP BY dept_store_chain_id ORDER BY count(*) DESC LIMIT 2 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Return the ids of the two department store chains with the most department stores. | SELECT dept_store_chain_id FROM department_stores GROUP BY dept_store_chain_id ORDER BY count(*) DESC LIMIT 2 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What is the id of the department with the least number of staff? | SELECT department_id FROM staff_department_assignments GROUP BY department_id ORDER BY count(*) LIMIT 1 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Return the id of the department with the fewest staff assignments. | SELECT department_id FROM staff_department_assignments GROUP BY department_id ORDER BY count(*) LIMIT 1 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | For each product type, return the maximum and minimum price. | SELECT product_type_code , max(product_price) , min(product_price) FROM products GROUP BY product_type_code | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the maximum and minimum product prices for each product type? | SELECT product_type_code , max(product_price) , min(product_price) FROM products GROUP BY product_type_code | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Find the product type whose average price is higher than the average price of all products. | SELECT product_type_code FROM products GROUP BY product_type_code HAVING avg(product_price) > (SELECT avg(product_price) FROM products) | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What is the code of the product type with an average price higher than the average price of all products? | SELECT product_type_code FROM products GROUP BY product_type_code HAVING avg(product_price) > (SELECT avg(product_price) FROM products) | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Find the id and name of the staff who has been assigned for the shortest period. | SELECT T1.staff_id , T1.staff_name FROM staff AS T1 JOIN Staff_Department_Assignments AS T2 ON T1.staff_id = T2.staff_id ORDER BY date_assigned_to - date_assigned_from LIMIT 1 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What is the id and name of the staff who has been assigned for the least amount of time? | SELECT T1.staff_id , T1.staff_name FROM staff AS T1 JOIN Staff_Department_Assignments AS T2 ON T1.staff_id = T2.staff_id ORDER BY date_assigned_to - date_assigned_from LIMIT 1 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Return the names and ids of all products whose price is between 600 and 700. | SELECT product_name , product_id FROM products WHERE product_price BETWEEN 600 AND 700 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the names and ids of products costing between 600 and 700? | SELECT product_name , product_id FROM products WHERE product_price BETWEEN 600 AND 700 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Find the ids of all distinct customers who made order after some orders that were Cancelled. | SELECT DISTINCT customer_id FROM Customer_Orders WHERE order_date > (SELECT min(order_date) FROM Customer_Orders WHERE order_status_code = "Cancelled") | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the distinct ids of customers who made an order after any order that was Cancelled? | SELECT DISTINCT customer_id FROM Customer_Orders WHERE order_date > (SELECT min(order_date) FROM Customer_Orders WHERE order_status_code = "Cancelled") | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What is id of the staff who had a Staff Department Assignment earlier than any Clerical Staff? | SELECT staff_id FROM Staff_Department_Assignments WHERE date_assigned_to < (SELECT max(date_assigned_to) FROM Staff_Department_Assignments WHERE job_title_code = 'Clerical Staff') | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Return the id of the staff whose Staff Department Assignment was earlier than that of any Clerical Staff. | SELECT staff_id FROM Staff_Department_Assignments WHERE date_assigned_to < (SELECT max(date_assigned_to) FROM Staff_Department_Assignments WHERE job_title_code = 'Clerical Staff') | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the names and ids of customers whose address contains TN? | SELECT customer_name , customer_id FROM customers WHERE customer_address LIKE "%TN%" | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Return the names and ids of customers who have TN in their address. | SELECT customer_name , customer_id FROM customers WHERE customer_address LIKE "%TN%" | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Return the name and gender of the staff who was assigned in 2016. | SELECT T1.staff_name , T1.staff_gender FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id = T2.staff_id WHERE T2.date_assigned_from LIKE "2016%" | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the names and genders of staff who were assigned in 2016? | SELECT T1.staff_name , T1.staff_gender FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id = T2.staff_id WHERE T2.date_assigned_from LIKE "2016%" | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | List the name of staff who has been assigned multiple jobs. | SELECT T1.staff_name FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id = T2.staff_id GROUP BY T2.staff_id HAVING COUNT (*) > 1 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the names of staff who have been assigned multiple jobs? | SELECT T1.staff_name FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id = T2.staff_id GROUP BY T2.staff_id HAVING COUNT (*) > 1 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | List the name and phone number of all suppliers in the alphabetical order of their addresses. | SELECT T1.supplier_name , T1.supplier_phone FROM Suppliers AS T1 JOIN supplier_addresses AS T2 ON T1.supplier_id = T2.supplier_id JOIN addresses AS T3 ON T2.address_id = T3.address_id ORDER BY T3.address_details | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the names and phone numbers for all suppliers, sorted in alphabetical order of their addressed? | SELECT T1.supplier_name , T1.supplier_phone FROM Suppliers AS T1 JOIN supplier_addresses AS T2 ON T1.supplier_id = T2.supplier_id JOIN addresses AS T3 ON T2.address_id = T3.address_id ORDER BY T3.address_details | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the phone numbers of all customers and suppliers. | SELECT customer_phone FROM customers UNION SELECT supplier_phone FROM suppliers | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Return the phone numbers for all customers and suppliers. | SELECT customer_phone FROM customers UNION SELECT supplier_phone FROM suppliers | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Return the ids of all products that were ordered more than three times or supplied more than 80000. | SELECT product_id FROM Order_Items GROUP BY product_id HAVING count(*) > 3 UNION SELECT product_id FROM Product_Suppliers GROUP BY product_id HAVING sum(total_amount_purchased) > 80000 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the ids of all products that were either ordered more than 3 times or have a cumulative amount purchased of above 80000? | SELECT product_id FROM Order_Items GROUP BY product_id HAVING count(*) > 3 UNION SELECT product_id FROM Product_Suppliers GROUP BY product_id HAVING sum(total_amount_purchased) > 80000 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are id and name of the products whose price is lower than 600 or higher than 900? | SELECT product_id , product_name FROM products WHERE product_price < 600 OR product_price > 900 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Give the ids and names of products with price lower than 600 or higher than 900. | SELECT product_id , product_name FROM products WHERE product_price < 600 OR product_price > 900 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Find the id of suppliers whose average amount purchased for each product is above 50000 or below 30000. | SELECT supplier_id FROM Product_Suppliers GROUP BY supplier_id HAVING avg(total_amount_purchased) > 50000 OR avg(total_amount_purchased) < 30000 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the ids of suppliers which have an average amount purchased of above 50000 or below 30000? | SELECT supplier_id FROM Product_Suppliers GROUP BY supplier_id HAVING avg(total_amount_purchased) > 50000 OR avg(total_amount_purchased) < 30000 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the average amount purchased and value purchased for the supplier who supplies the most products. | SELECT avg(total_amount_purchased) , avg(total_value_purchased) FROM Product_Suppliers WHERE supplier_id = (SELECT supplier_id FROM Product_Suppliers GROUP BY supplier_id ORDER BY count(*) DESC LIMIT 1) | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Return the average total amount purchased and total value purchased for the supplier who supplies the greatest number of products. | SELECT avg(total_amount_purchased) , avg(total_value_purchased) FROM Product_Suppliers WHERE supplier_id = (SELECT supplier_id FROM Product_Suppliers GROUP BY supplier_id ORDER BY count(*) DESC LIMIT 1) | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What is the largest and smallest customer codes? | SELECT max(customer_code) , min(customer_code) FROM Customers | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Return the maximum and minimum customer codes. | SELECT max(customer_code) , min(customer_code) FROM Customers | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | List the names of all the distinct customers who bought a keyboard. | SELECT DISTINCT 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 JOIN products AS T4 ON T3.product_id = T4.product_id WHERE T4.product_name = "keyboard" | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the distinct names of customers who have purchased a keyboard? | SELECT DISTINCT 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 JOIN products AS T4 ON T3.product_id = T4.product_id WHERE T4.product_name = "keyboard" | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | List the names and phone numbers of all the distinct suppliers who supply red jeans. | SELECT DISTINCT T1.supplier_name , T1.supplier_phone FROM suppliers AS T1 JOIN product_suppliers AS T2 ON T1.supplier_id = T2.supplier_id JOIN products AS T3 ON T2.product_id = T3.product_id WHERE T3.product_name = "red jeans" | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the distinct names and phone numbers for suppliers who have red jeans? | SELECT DISTINCT T1.supplier_name , T1.supplier_phone FROM suppliers AS T1 JOIN product_suppliers AS T2 ON T1.supplier_id = T2.supplier_id JOIN products AS T3 ON T2.product_id = T3.product_id WHERE T3.product_name = "red jeans" | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the highest and lowest prices of products, grouped by and alphabetically ordered by product type? | SELECT max(product_price) , min(product_price) , product_type_code FROM products GROUP BY product_type_code ORDER BY product_type_code | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Give the maximum and minimum product prices for each product type, grouped and ordered by product type. | SELECT max(product_price) , min(product_price) , product_type_code FROM products GROUP BY product_type_code ORDER BY product_type_code | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | List the order id, customer id for orders in Cancelled status, ordered by their order dates. | SELECT order_id , customer_id FROM customer_orders WHERE order_status_code = "Cancelled" ORDER BY order_date | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the order ids and customer ids for orders that have been Cancelled, sorted by their order dates? | SELECT order_id , customer_id FROM customer_orders WHERE order_status_code = "Cancelled" ORDER BY order_date | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Find the names of products that were bought by at least two distinct customers. | SELECT DISTINCT T3.product_name FROM customer_orders AS T1 JOIN order_items AS T2 ON T1.order_id = T2.order_id JOIN products AS T3 ON T2.product_id = T3.product_id GROUP BY T3.product_id HAVING COUNT (DISTINCT T1.customer_id) >= 2 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the distinct names of products purchased by at least two different customers? | SELECT DISTINCT T3.product_name FROM customer_orders AS T1 JOIN order_items AS T2 ON T1.order_id = T2.order_id JOIN products AS T3 ON T2.product_id = T3.product_id GROUP BY T3.product_id HAVING COUNT (DISTINCT T1.customer_id) >= 2 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Find the names of customers who have bought by at least three distinct products. | SELECT DISTINCT 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_id HAVING COUNT (DISTINCT T3.product_id) >= 3 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the distinct names of customers who have purchased at least three different products? | SELECT DISTINCT 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_id HAVING COUNT (DISTINCT T3.product_id) >= 3 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Find the name and gender of the staff who has been assigned the job of Sales Person but never Clerical Staff. | SELECT T1.staff_name , T1.staff_gender FROM staff AS T1 JOIN Staff_Department_Assignments AS T2 ON T1.staff_id = T2.staff_id WHERE T2.job_title_code = "Sales Person" EXCEPT SELECT T1.staff_name , T1.staff_gender FROM staff AS T1 JOIN Staff_Department_Assignments AS T2 ON T1.staff_id = T2.staff_id WHERE T2.job_title_code = "Clerical Staff" | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the names and genders of staff who have held the title Sales Person, but never Clerical Staff? | SELECT T1.staff_name , T1.staff_gender FROM staff AS T1 JOIN Staff_Department_Assignments AS T2 ON T1.staff_id = T2.staff_id WHERE T2.job_title_code = "Sales Person" EXCEPT SELECT T1.staff_name , T1.staff_gender FROM staff AS T1 JOIN Staff_Department_Assignments AS T2 ON T1.staff_id = T2.staff_id WHERE T2.job_title_code = "Clerical Staff" | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Find the id and name of customers whose address contains WY state and do not use credit card for payment. | SELECT customer_id , customer_name FROM customers WHERE customer_address LIKE "%WY%" AND payment_method_code != "Credit Card" | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What are the ids and names of customers with addressed that contain WY and who do not use a credit card for payment? | SELECT customer_id , customer_name FROM customers WHERE customer_address LIKE "%WY%" AND payment_method_code != "Credit Card" | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Find the average price of all product clothes. | SELECT avg(product_price) FROM products WHERE product_type_code = 'Clothes' | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What is the average price of clothes? | SELECT avg(product_price) FROM products WHERE product_type_code = 'Clothes' | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | Find the name of the most expensive hardware product. | SELECT product_name FROM products WHERE product_type_code = 'Hardware' ORDER BY product_price DESC LIMIT 1 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
department_store | What is the name of the hardware product with the greatest price? | SELECT product_name FROM products WHERE product_type_code = 'Hardware' ORDER BY product_price DESC LIMIT 1 | CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
3 rows from Addresses table:
address_id address_details
1 28481 Crist Circle\nEast Burdettestad, IA 21232
2 0292 Mitchel Pike\nPort Abefurt, IA 84402-4249
3 4062 Mante Place\nWest Lindsey, DE 76199-8015
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`staff_gender` VARCHAR(1),
`staff_name` VARCHAR(80)
)
3 rows from Staff table:
staff_id staff_gender staff_name
1 1 Tom
2 1 Malika
3 1 Katelynn
CREATE TABLE `Suppliers` (
`supplier_id` INTEGER PRIMARY KEY,
`supplier_name` VARCHAR(80),
`supplier_phone` VARCHAR(80)
)
3 rows from Suppliers table:
supplier_id supplier_name supplier_phone
1 Lidl (692)009-5928
2 AB Store 1-483-283-4742
3 Tesco 287-071-1153x254
CREATE TABLE `Department_Store_Chain` (
`dept_store_chain_id` INTEGER PRIMARY KEY,
`dept_store_chain_name` VARCHAR(80)
)
3 rows from Department_Store_Chain table:
dept_store_chain_id dept_store_chain_name
1 South
2 West
3 East
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`payment_method_code` VARCHAR(10) NOT NULL,
`customer_code` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
3 rows from Customers table:
customer_id payment_method_code customer_code customer_name customer_address customer_phone customer_email
1 Credit Card 401 Ahmed 75099 Tremblay Port Apt. 163\nSouth Norrisland, SC 80546 254-072-4068x33935 margarett.vonrueden@example.com
2 Credit Card 665 Chauncey 8408 Lindsay Court\nEast Dasiabury, IL 72656-3552 +41(8)1897032009 stiedemann.sigrid@example.com
3 Direct Debit 844 Lukas 7162 Rodolfo Knoll Apt. 502\nLake Annalise, TN 35791-8871 197-417-3557 joelle.monahan@example.com
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(10) NOT NULL,
`product_name` VARCHAR(80),
`product_price` DECIMAL(19,4)
)
3 rows from Products table:
product_id product_type_code product_name product_price
1 Clothes red jeans 734.73
2 Clothes yellow jeans 687.23
3 Clothes black jeans 695.16
CREATE TABLE `Supplier_Addresses` (
`supplier_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`supplier_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` )
)
3 rows from Supplier_Addresses table:
supplier_id address_id date_from date_to
4 5 2016-09-22 16:41:31 2018-03-14 20:06:37
3 9 2014-11-07 19:18:49 2018-03-16 16:39:58
3 2 2008-11-22 12:01:25 2018-03-02 19:50:22
CREATE TABLE `Customer_Addresses` (
`customer_id` INTEGER NOT NULL,
`address_id` INTEGER NOT NULL,
`date_from` DATETIME NOT NULL,
`date_to` DATETIME,
PRIMARY KEY (`customer_id`, `address_id`),
FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Addresses table:
customer_id address_id date_from date_to
2 9 2017-12-11 05:00:22 2018-03-20 20:52:34
1 6 2017-10-07 23:00:26 2018-02-28 14:53:52
10 8 2017-04-04 20:00:27 2018-02-27 20:08:33
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_status_code` VARCHAR(10) NOT NULL,
`order_date` DATETIME NOT NULL,
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
3 rows from Customer_Orders table:
order_id customer_id order_status_code order_date
1 12 Completed 2018-02-10 15:44:48
2 4 New 2018-01-31 17:49:18
3 1 PartFilled 2018-02-26 12:39:33
CREATE TABLE `Department_Stores` (
`dept_store_id` INTEGER PRIMARY KEY,
`dept_store_chain_id` INTEGER,
`store_name` VARCHAR(80),
`store_address` VARCHAR(255),
`store_phone` VARCHAR(80),
`store_email` VARCHAR(80),
FOREIGN KEY (`dept_store_chain_id` ) REFERENCES `Department_Store_Chain`(`dept_store_chain_id` )
)
3 rows from Department_Stores table:
dept_store_id dept_store_chain_id store_name store_address store_phone store_email
1 1 store_name 01290 Jeremie Parkway Suite 753\nNorth Arielle, MS 51249 (948)944-5099x2027 bmaggio@example.com
2 3 store_name 082 Purdy Expressway\nO'Connellshire, IL 31732 877-917-5029 larissa10@example.org
3 4 store_name 994 Travis Plains\nNorth Wadeton, WV 27575-3951 1-216-312-0375 alexandro.mcclure@example.net
CREATE TABLE `Departments` (
`department_id` INTEGER PRIMARY KEY,
`dept_store_id` INTEGER NOT NULL,
`department_name` VARCHAR(80),
FOREIGN KEY (`dept_store_id` ) REFERENCES `Department_Stores`(`dept_store_id` )
)
3 rows from Departments table:
department_id dept_store_id department_name
1 5 human resource
2 11 purchasing
3 4 marketing
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Order_Items table:
order_item_id order_id product_id
1 9 7
2 1 3
3 5 2
CREATE TABLE `Product_Suppliers` (
`product_id` INTEGER NOT NULL,
`supplier_id` INTEGER NOT NULL,
`date_supplied_from` DATETIME NOT NULL,
`date_supplied_to` DATETIME,
`total_amount_purchased` VARCHAR(80),
`total_value_purchased` DECIMAL(19,4),
PRIMARY KEY (`product_id`, `supplier_id`),
FOREIGN KEY (`supplier_id` ) REFERENCES `Suppliers`(`supplier_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
3 rows from Product_Suppliers table:
product_id supplier_id date_supplied_from date_supplied_to total_amount_purchased total_value_purchased
4 3 2017-06-19 00:49:05 2018-03-24 19:29:18 89366.05 36014.60
8 4 2017-07-02 00:35:12 2018-03-25 07:30:49 25085.57 36274.56
3 3 2017-10-14 19:15:37 2018-03-24 02:29:44 15752.45 7273.74
CREATE TABLE `Staff_Department_Assignments` (
`staff_id` INTEGER NOT NULL,
`department_id` INTEGER NOT NULL,
`date_assigned_from` DATETIME NOT NULL,
`job_title_code` VARCHAR(10) NOT NULL,
`date_assigned_to` DATETIME,
PRIMARY KEY (`staff_id`, `department_id`),
FOREIGN KEY (`department_id` ) REFERENCES `Departments`(`department_id` ),
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` )
)
3 rows from Staff_Department_Assignments table:
staff_id department_id date_assigned_from job_title_code date_assigned_to
5 4 2017-06-11 22:55:20 Department Manager 2018-03-23 21:59:11
10 5 2017-12-18 19:12:15 Sales Person 2018-03-23 20:25:24
1 5 2018-02-14 03:15:29 Clerical Staff 2018-03-24 19:57:56
|
aircraft | How many aircrafts are there? | SELECT count(*) FROM aircraft | CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
)
3 rows from pilot table:
Pilot_Id Name Age
1 Prof. Zackery Collins 23
2 Katheryn Gorczany IV 20
3 Mr. Cristian Halvorson II 23
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
)
3 rows from aircraft table:
Aircraft_ID Aircraft Description Max_Gross_Weight Total_disk_area Max_disk_Loading
1 Robinson R-22 Light utility helicopter 1,370 lb (635 kg) 497 ft² (46.2 m²) 2.6 lb/ft² (14 kg/m²)
2 Bell 206B3 JetRanger Turboshaft utility helicopter 3,200 lb (1,451 kg) 872 ft² (81.1 m²) 3.7 lb/ft² (18 kg/m²)
3 CH-47D Chinook Tandem rotor helicopter 50,000 lb (22,680 kg) 5,655 ft² (526 m²) 8.8 lb/ft² (43 kg/m²)
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
)
3 rows from match table:
Round Location Country Date Fastest_Qualifying Winning_Pilot Winning_Aircraft
1.0 Mina' Zayid , Abu Dhabi United Arab Emirates March 26–27 Hannes Arch 1 1
2.0 Swan River , Perth Australia April 17–18 Paul Bonhomme 4 1
3.0 Flamengo Beach , Rio de Janeiro Brazil May 8–9 Hannes Arch 6 2
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
)
3 rows from airport table:
Airport_ID Airport_Name Total_Passengers %_Change_2007 International_Passengers Domestic_Passengers Transit_Passengers Aircraft_Movements Freight_Metric_Tonnes
1 London Heathrow 67054745.0 1.5% 61344438.0 5562516.0 147791.0 478693.0 1397054.0
2 London Gatwick 34205887.0 2.9% 30431051.0 3730963.0 43873.0 263653.0 107702.0
3 London Stansted 22360364.0 6.0% 19996947.0 2343428.0 19989.0 193282.0 197738.0
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
)
3 rows from airport_aircraft table:
ID Airport_ID Aircraft_ID
1 6 5
2 2 1
3 1 2
|
aircraft | What is the number of aircraft? | SELECT count(*) FROM aircraft | CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
)
3 rows from pilot table:
Pilot_Id Name Age
1 Prof. Zackery Collins 23
2 Katheryn Gorczany IV 20
3 Mr. Cristian Halvorson II 23
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
)
3 rows from aircraft table:
Aircraft_ID Aircraft Description Max_Gross_Weight Total_disk_area Max_disk_Loading
1 Robinson R-22 Light utility helicopter 1,370 lb (635 kg) 497 ft² (46.2 m²) 2.6 lb/ft² (14 kg/m²)
2 Bell 206B3 JetRanger Turboshaft utility helicopter 3,200 lb (1,451 kg) 872 ft² (81.1 m²) 3.7 lb/ft² (18 kg/m²)
3 CH-47D Chinook Tandem rotor helicopter 50,000 lb (22,680 kg) 5,655 ft² (526 m²) 8.8 lb/ft² (43 kg/m²)
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
)
3 rows from match table:
Round Location Country Date Fastest_Qualifying Winning_Pilot Winning_Aircraft
1.0 Mina' Zayid , Abu Dhabi United Arab Emirates March 26–27 Hannes Arch 1 1
2.0 Swan River , Perth Australia April 17–18 Paul Bonhomme 4 1
3.0 Flamengo Beach , Rio de Janeiro Brazil May 8–9 Hannes Arch 6 2
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
)
3 rows from airport table:
Airport_ID Airport_Name Total_Passengers %_Change_2007 International_Passengers Domestic_Passengers Transit_Passengers Aircraft_Movements Freight_Metric_Tonnes
1 London Heathrow 67054745.0 1.5% 61344438.0 5562516.0 147791.0 478693.0 1397054.0
2 London Gatwick 34205887.0 2.9% 30431051.0 3730963.0 43873.0 263653.0 107702.0
3 London Stansted 22360364.0 6.0% 19996947.0 2343428.0 19989.0 193282.0 197738.0
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
)
3 rows from airport_aircraft table:
ID Airport_ID Aircraft_ID
1 6 5
2 2 1
3 1 2
|
aircraft | List the description of all aircrafts. | SELECT Description FROM aircraft | CREATE TABLE `pilot` (
`Pilot_Id` int(11) NOT NULL,
`Name` varchar(50) NOT NULL,
`Age` int(11) NOT NULL,
PRIMARY KEY (`Pilot_Id`)
)
3 rows from pilot table:
Pilot_Id Name Age
1 Prof. Zackery Collins 23
2 Katheryn Gorczany IV 20
3 Mr. Cristian Halvorson II 23
CREATE TABLE `aircraft` (
"Aircraft_ID" int(11) NOT NULL,
"Aircraft" varchar(50) NOT NULL,
"Description" varchar(50) NOT NULL,
"Max_Gross_Weight" varchar(50) NOT NULL,
"Total_disk_area" varchar(50) NOT NULL,
"Max_disk_Loading" varchar(50) NOT NULL,
PRIMARY KEY (`Aircraft_ID`)
)
3 rows from aircraft table:
Aircraft_ID Aircraft Description Max_Gross_Weight Total_disk_area Max_disk_Loading
1 Robinson R-22 Light utility helicopter 1,370 lb (635 kg) 497 ft² (46.2 m²) 2.6 lb/ft² (14 kg/m²)
2 Bell 206B3 JetRanger Turboshaft utility helicopter 3,200 lb (1,451 kg) 872 ft² (81.1 m²) 3.7 lb/ft² (18 kg/m²)
3 CH-47D Chinook Tandem rotor helicopter 50,000 lb (22,680 kg) 5,655 ft² (526 m²) 8.8 lb/ft² (43 kg/m²)
CREATE TABLE `match` (
"Round" real,
"Location" text,
"Country" text,
"Date" text,
"Fastest_Qualifying" text,
"Winning_Pilot" text,
"Winning_Aircraft" text,
PRIMARY KEY ("Round"),
FOREIGN KEY (`Winning_Aircraft`) REFERENCES `aircraft`(`Aircraft_ID`),
FOREIGN KEY (`Winning_Pilot`) REFERENCES `pilot`(`Pilot_Id`)
)
3 rows from match table:
Round Location Country Date Fastest_Qualifying Winning_Pilot Winning_Aircraft
1.0 Mina' Zayid , Abu Dhabi United Arab Emirates March 26–27 Hannes Arch 1 1
2.0 Swan River , Perth Australia April 17–18 Paul Bonhomme 4 1
3.0 Flamengo Beach , Rio de Janeiro Brazil May 8–9 Hannes Arch 6 2
CREATE TABLE `airport` (
"Airport_ID" int,
"Airport_Name" text,
"Total_Passengers" real,
"%_Change_2007" text,
"International_Passengers" real,
"Domestic_Passengers" real,
"Transit_Passengers" real,
"Aircraft_Movements" real,
"Freight_Metric_Tonnes" real,
PRIMARY KEY ("Airport_ID")
)
3 rows from airport table:
Airport_ID Airport_Name Total_Passengers %_Change_2007 International_Passengers Domestic_Passengers Transit_Passengers Aircraft_Movements Freight_Metric_Tonnes
1 London Heathrow 67054745.0 1.5% 61344438.0 5562516.0 147791.0 478693.0 1397054.0
2 London Gatwick 34205887.0 2.9% 30431051.0 3730963.0 43873.0 263653.0 107702.0
3 London Stansted 22360364.0 6.0% 19996947.0 2343428.0 19989.0 193282.0 197738.0
CREATE TABLE `airport_aircraft` (
"ID" int,
"Airport_ID" int,
"Aircraft_ID" int,
PRIMARY KEY ("Airport_ID","Aircraft_ID"),
FOREIGN KEY ("Airport_ID") REFERENCES `airport`(`Airport_ID`),
FOREIGN KEY ("Aircraft_ID") REFERENCES `aircraft`(`Aircraft_ID`)
)
3 rows from airport_aircraft table:
ID Airport_ID Aircraft_ID
1 6 5
2 2 1
3 1 2
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.