db_id
stringclasses 127
values | query
stringlengths 20
523
| question
stringlengths 16
224
| schema
stringclasses 127
values |
---|---|---|---|
dorm_1
|
SELECT count(*) , sum(student_capacity) , gender FROM dorm GROUP BY gender
|
Find the number of dorms and total capacity for each gender.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT count(*) , sum(student_capacity) , gender FROM dorm GROUP BY gender
|
How many dorms are there and what is the total capacity for each gender?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT avg(age) , max(age) , sex FROM student GROUP BY sex
|
Find the average and oldest age for students with different sex.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT avg(age) , max(age) , sex FROM student GROUP BY sex
|
What is the average and oldest age for each gender of student?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT count(*) , major FROM student GROUP BY major
|
Find the number of students in each major.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT count(*) , major FROM student GROUP BY major
|
How many students are there in each major?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT count(*) , avg(age) , city_code FROM student GROUP BY city_code
|
Find the number and average age of students living in each city.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT count(*) , avg(age) , city_code FROM student GROUP BY city_code
|
How many students live in each city and what are their average ages?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT count(*) , avg(age) , city_code FROM student WHERE sex = 'M' GROUP BY city_code
|
Find the average age and number of male students (with sex M) from each city.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT count(*) , avg(age) , city_code FROM student WHERE sex = 'M' GROUP BY city_code
|
What is the average age and how many male students are there in each city?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT count(*) , city_code FROM student GROUP BY city_code HAVING count(*) > 1
|
Find the number of students for the cities where have more than one student.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT count(*) , city_code FROM student GROUP BY city_code HAVING count(*) > 1
|
How many students are from each city, and which cities have more than one cities?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT fname , lname FROM student WHERE major != (SELECT major FROM student GROUP BY major ORDER BY count(*) DESC LIMIT 1)
|
Find the first and last name of students who are not in the largest major.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT fname , lname FROM student WHERE major != (SELECT major FROM student GROUP BY major ORDER BY count(*) DESC LIMIT 1)
|
What is the first and last name of the students who are not in the largest major?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT count(*) , sex FROM student WHERE age > (SELECT avg(age) FROM student) GROUP BY sex
|
Find the number of students whose age is older than the average age for each gender.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT count(*) , sex FROM student WHERE age > (SELECT avg(age) FROM student) GROUP BY sex
|
How many students are older than average for each gender?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT avg(T1.age) , T3.dorm_name FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid JOIN dorm AS T3 ON T3.dormid = T2.dormid GROUP BY T3.dorm_name
|
Find the average age of students living in each dorm and the name of dorm.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT avg(T1.age) , T3.dorm_name FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid JOIN dorm AS T3 ON T3.dormid = T2.dormid GROUP BY T3.dorm_name
|
What is the average age for each dorm and what are the names of each dorm?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT count(*) , T1.dormid FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid WHERE T1.student_capacity > 100 GROUP BY T1.dormid
|
Find the number of amenities for each of the dorms that can accommodate more than 100 students.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT count(*) , T1.dormid FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid WHERE T1.student_capacity > 100 GROUP BY T1.dormid
|
For each dorm, how many amenities does it have?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT count(*) , T3.dorm_name FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid JOIN dorm AS T3 ON T3.dormid = T2.dormid WHERE T1.age > 20 GROUP BY T3.dorm_name
|
Find the number of students who is older than 20 in each dorm.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT count(*) , T3.dorm_name FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid JOIN dorm AS T3 ON T3.dormid = T2.dormid WHERE T1.age > 20 GROUP BY T3.dorm_name
|
How many students are older than 20 in each dorm?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT T1.fname FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid JOIN dorm AS T3 ON T3.dormid = T2.dormid WHERE T3.dorm_name = 'Smith Hall'
|
Find the first name of students who are living in the Smith Hall.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT T1.fname FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid JOIN dorm AS T3 ON T3.dormid = T2.dormid WHERE T3.dorm_name = 'Smith Hall'
|
What are the first names of all students in Smith Hall?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT avg(T1.age) FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid JOIN dorm AS T3 ON T3.dormid = T2.dormid WHERE T3.student_capacity = (SELECT max(student_capacity) FROM dorm)
|
Find the average age of students who are living in the dorm with the largest capacity.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT avg(T1.age) FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid JOIN dorm AS T3 ON T3.dormid = T2.dormid WHERE T3.student_capacity = (SELECT max(student_capacity) FROM dorm)
|
What is the average age of students who are living in the dorm with the largest capacity?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT count(*) FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid JOIN dorm AS T3 ON T3.dormid = T2.dormid WHERE T3.gender = 'M'
|
Find the total number of students living in the male dorm (with gender M).
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT count(*) FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid JOIN dorm AS T3 ON T3.dormid = T2.dormid WHERE T3.gender = 'M'
|
What are the total number of students who are living in a male dorm?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT count(*) FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid JOIN dorm AS T3 ON T3.dormid = T2.dormid WHERE T3.dorm_name = 'Smith Hall' AND T1.sex = 'F'
|
Find the number of female students (with F sex) living in Smith Hall
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT count(*) FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid JOIN dorm AS T3 ON T3.dormid = T2.dormid WHERE T3.dorm_name = 'Smith Hall' AND T1.sex = 'F'
|
How many female students live in Smith Hall?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT T3.amenity_name FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid WHERE T1.dorm_name = 'Smith Hall'
|
Find the name of amenities Smith Hall dorm have.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT T3.amenity_name FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid WHERE T1.dorm_name = 'Smith Hall'
|
What are the names of the amenities that Smith Hall has?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT T3.amenity_name FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid WHERE T1.dorm_name = 'Smith Hall' ORDER BY T3.amenity_name
|
Find the name of amenities Smith Hall dorm have. ordered the results by amenity names.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT T3.amenity_name FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid WHERE T1.dorm_name = 'Smith Hall' ORDER BY T3.amenity_name
|
What amenities does Smith Hall have in alphabetical order?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT T1.amenity_name FROM dorm_amenity AS T1 JOIN has_amenity AS T2 ON T1.amenid = T2.amenid GROUP BY T2.amenid ORDER BY count(*) DESC LIMIT 1
|
Find the name of amenity that is most common in all dorms.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT T1.amenity_name FROM dorm_amenity AS T1 JOIN has_amenity AS T2 ON T1.amenid = T2.amenid GROUP BY T2.amenid ORDER BY count(*) DESC LIMIT 1
|
What is the most common amenity in the dorms?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT T1.fname FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid WHERE T2.dormid IN (SELECT T2.dormid FROM dorm AS T3 JOIN has_amenity AS T4 ON T3.dormid = T4.dormid JOIN dorm_amenity AS T5 ON T4.amenid = T5.amenid GROUP BY T3.dormid ORDER BY count(*) DESC LIMIT 1)
|
Find the first name of students who are living in the dorm that has most number of amenities.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT T1.fname FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid WHERE T2.dormid IN (SELECT T2.dormid FROM dorm AS T3 JOIN has_amenity AS T4 ON T3.dormid = T4.dormid JOIN dorm_amenity AS T5 ON T4.amenid = T5.amenid GROUP BY T3.dormid ORDER BY count(*) DESC LIMIT 1)
|
What are the first names of all students who live in the dorm with the most amenities?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT T1.dorm_name , T1.student_capacity FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid GROUP BY T2.dormid ORDER BY count(*) LIMIT 1
|
Find the name and capacity of the dorm with least number of amenities.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT T1.dorm_name , T1.student_capacity FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid GROUP BY T2.dormid ORDER BY count(*) LIMIT 1
|
What is the name and capacity of the dorm with the fewest amount of amenities?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT dorm_name FROM dorm EXCEPT SELECT T1.dorm_name FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid WHERE T3.amenity_name = 'TV Lounge'
|
Find the name of dorms that do not have amenity TV Lounge.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT dorm_name FROM dorm EXCEPT SELECT T1.dorm_name FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid WHERE T3.amenity_name = 'TV Lounge'
|
What are the names of the dorm that does not have a TV Lounge?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT T1.fname , T1.lname FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid WHERE T2.dormid IN (SELECT T3.dormid FROM has_amenity AS T3 JOIN dorm_amenity AS T4 ON T3.amenid = T4.amenid WHERE T4.amenity_name = 'TV Lounge')
|
Find the first and last name of students who are living in the dorms that have amenity TV Lounge.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT T1.fname , T1.lname FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid WHERE T2.dormid IN (SELECT T3.dormid FROM has_amenity AS T3 JOIN dorm_amenity AS T4 ON T3.amenid = T4.amenid WHERE T4.amenity_name = 'TV Lounge')
|
What are the first and last names of all students who are living in a dorm with a TV Lounge?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT T1.fname , T1.age FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid WHERE T2.dormid NOT IN (SELECT T3.dormid FROM has_amenity AS T3 JOIN dorm_amenity AS T4 ON T3.amenid = T4.amenid WHERE T4.amenity_name = 'TV Lounge')
|
Find the first name and age of students who are living in the dorms that do not have amenity TV Lounge.
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT T1.fname , T1.age FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid WHERE T2.dormid NOT IN (SELECT T3.dormid FROM has_amenity AS T3 JOIN dorm_amenity AS T4 ON T3.amenid = T4.amenid WHERE T4.amenity_name = 'TV Lounge')
|
What is the first name and age of every student who lives in a dorm with a TV Lounge?
|
create table Student (
StuID INTEGER PRIMARY KEY,
LName VARCHAR(12),
Fname VARCHAR(12),
Age INTEGER,
Sex VARCHAR(1),
Major INTEGER,
Advisor INTEGER,
city_code VARCHAR(3)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT T3.amenity_name FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid JOIN lives_in AS T4 ON T4.dormid = T1.dormid JOIN student AS T5 ON T5.stuid = T4.stuid WHERE T5.lname = 'Smith'
|
Find the name of amenities of the dorm where the student with last name Smith is living 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)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
dorm_1
|
SELECT T3.amenity_name FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid JOIN lives_in AS T4 ON T4.dormid = T1.dormid JOIN student AS T5 ON T5.stuid = T4.stuid WHERE T5.lname = 'Smith'
|
What are the amenities in the dorm that a student who has the last name of Smith lives 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)
);
create table Dorm (
dormid INTEGER,
dorm_name VARCHAR(20),
student_capacity INTEGER,
gender VARCHAR(1)
) ;
create table Dorm_amenity (
amenid INTEGER,
amenity_name VARCHAR(25)
) ;
create table Has_amenity (
dormid INTEGER,
amenid INTEGER,
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid),
FOREIGN KEY (amenid) REFERENCES `Dorm_amenity`(amenid)
);
create table Lives_in (
stuid INTEGER,
dormid INTEGER,
room_number INTEGER,
FOREIGN KEY (stuid) REFERENCES `Student`(StuID),
FOREIGN KEY (dormid) REFERENCES `Dorm`(dormid)
);
insert into Student values ( 1001, 'Smith', 'Linda', 18, 'F', 600, 1121,'BAL');
insert into Dorm values (100,'Smith Hall',85,'X');
insert into Dorm_amenity values ( 900 , 'TV Lounge' ) ;
insert into Has_amenity values ( 109 , 900) ;
insert into Lives_in values ( 1001 , 109 , 105 ) ;
INSERT INTO Student VALUES [(1001, 'Smith', 'Linda', 18, 'F', 600, 1121, 'BAL'), (1002, 'Kim', 'Tracy', 19, 'F', 600, 7712, 'HKG')]
INSERT INTO Dorm VALUES [(100, 'Smith Hall', 85, 'X'), (110, 'Bud Jones Hall', 116, 'M')]
INSERT INTO Dorm_amenity VALUES [(900, 'TV Lounge'), (901, 'Study Room')]
INSERT INTO Has_amenity VALUES [(109, 900), (109, 901)]
INSERT INTO Lives_in VALUES [(1001, 109, 105), (1002, 100, 112)]
|
customer_complaints
|
SELECT count(*) FROM customers
|
How many customers are there?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT count(*) FROM customers
|
Count the number of customers.
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT email_address , phone_number FROM customers ORDER BY email_address , phone_number
|
Find the emails and phone numbers of all the customers, ordered by email address and phone number.
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT email_address , phone_number FROM customers ORDER BY email_address , phone_number
|
What are the emails and phone numbers of all customers, sorted by email address and phone number?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT town_city FROM customers WHERE customer_type_code = "Good Credit Rating" GROUP BY town_city ORDER BY count(*) LIMIT 1
|
Which city has the least number of customers whose type code is "Good Credit Rating"?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT town_city FROM customers WHERE customer_type_code = "Good Credit Rating" GROUP BY town_city ORDER BY count(*) LIMIT 1
|
Return the city with the customer type code "Good Credit Rating" that had the fewest customers.
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT t1.product_name , count(*) FROM products AS t1 JOIN complaints AS t2 ON t1.product_id = t2.product_id GROUP BY t1.product_name
|
List the name of all products along with the number of complaints that they have received.
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT t1.product_name , count(*) FROM products AS t1 JOIN complaints AS t2 ON t1.product_id = t2.product_id GROUP BY t1.product_name
|
What are all the different product names, and how many complains has each received?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT t1.email_address FROM customers AS t1 JOIN complaints AS t2 ON t1.customer_id = t2.customer_id GROUP BY t1.customer_id ORDER BY count(*) LIMIT 1
|
Find the emails of customers who has filed a complaints of the product with the most complaints.
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT t1.email_address FROM customers AS t1 JOIN complaints AS t2 ON t1.customer_id = t2.customer_id GROUP BY t1.customer_id ORDER BY count(*) LIMIT 1
|
What are the emails of customers who have filed complaints on the product which has had the greatest number of complaints?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT DISTINCT t1.product_name FROM products AS t1 JOIN complaints AS t2 ON t1.product_id = t2.product_id JOIN customers AS t3 GROUP BY t3.customer_id ORDER BY count(*) LIMIT 1
|
Which products has been complained by the customer who has filed least amount of complaints?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT DISTINCT t1.product_name FROM products AS t1 JOIN complaints AS t2 ON t1.product_id = t2.product_id JOIN customers AS t3 GROUP BY t3.customer_id ORDER BY count(*) LIMIT 1
|
Return the names of products that have had complaints filed by the customer who has filed the fewest complaints.
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT t1.phone_number FROM customers AS t1 JOIN complaints AS t2 ON t1.customer_id = t2.customer_id ORDER BY t2.date_complaint_raised DESC LIMIT 1
|
What is the phone number of the customer who has filed the most recent complaint?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT t1.phone_number FROM customers AS t1 JOIN complaints AS t2 ON t1.customer_id = t2.customer_id ORDER BY t2.date_complaint_raised DESC LIMIT 1
|
Return the phone number of the customer who filed the complaint that was raised most recently.
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT email_address , phone_number FROM customers WHERE customer_id NOT IN (SELECT customer_id FROM complaints)
|
Find the email and phone number of the customers who have never filed a complaint before.
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT email_address , phone_number FROM customers WHERE customer_id NOT IN (SELECT customer_id FROM complaints)
|
What are the emails and phone numbers of custoemrs who have never filed a complaint?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT phone_number FROM customers UNION SELECT phone_number FROM staff
|
Find the phone number of all the customers and staff.
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT phone_number FROM customers UNION SELECT phone_number FROM staff
|
What are the phone numbers of all customers and all staff members?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT product_description FROM products WHERE product_name = "Chocolate"
|
What is the description of the product named "Chocolate"?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT product_description FROM products WHERE product_name = "Chocolate"
|
Return the description of the product called "Chocolate".
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT product_name , product_category_code FROM products ORDER BY product_price DESC LIMIT 1
|
Find the name and category of the most expensive product.
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT product_name , product_category_code FROM products ORDER BY product_price DESC LIMIT 1
|
What is the name and category code of the product with the highest price?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT product_price FROM products WHERE product_id NOT IN (SELECT product_id FROM complaints)
|
Find the prices of products which has never received a single complaint.
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT product_price FROM products WHERE product_id NOT IN (SELECT product_id FROM complaints)
|
What are the prices of products that have never gotten a complaint?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT avg(product_price) , product_category_code FROM products GROUP BY product_category_code
|
What is the average price of the products for each category?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT avg(product_price) , product_category_code FROM products GROUP BY product_category_code
|
Return the average price of products that have each category code.
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT t1.last_name FROM staff AS t1 JOIN complaints AS t2 ON t1.staff_id = t2.staff_id JOIN products AS t3 ON t2.product_id = t3.product_id ORDER BY t3.product_price LIMIT 1
|
Find the last name of the staff member who processed the complaint of the cheapest product.
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT t1.last_name FROM staff AS t1 JOIN complaints AS t2 ON t1.staff_id = t2.staff_id JOIN products AS t3 ON t2.product_id = t3.product_id ORDER BY t3.product_price LIMIT 1
|
What is the last name of the staff member in charge of the complaint on the product with the lowest price?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT complaint_status_code FROM complaints GROUP BY complaint_status_code HAVING count(*) > 3
|
Which complaint status has more than 3 records on file?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT complaint_status_code FROM complaints GROUP BY complaint_status_code HAVING count(*) > 3
|
Return complaint status codes have more than 3 corresponding complaints?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT last_name FROM staff WHERE email_address LIKE "%wrau%"
|
Find the last name of the staff whose email address contains "wrau".
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT last_name FROM staff WHERE email_address LIKE "%wrau%"
|
What are the last names of staff with email addressed containing the substring "wrau"?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT count(*) FROM customers GROUP BY customer_type_code ORDER BY count(*) DESC LIMIT 1
|
How many customers are there in the customer type with the most customers?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT count(*) FROM customers GROUP BY customer_type_code ORDER BY count(*) DESC LIMIT 1
|
Count the number of customers that have the customer type that is most common.
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT t1.last_name FROM staff AS t1 JOIN complaints AS t2 ON t1.staff_id = t2.staff_id ORDER BY t2.date_complaint_raised LIMIT 1
|
What is the last name of the staff who has handled the first ever complaint?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT t1.last_name FROM staff AS t1 JOIN complaints AS t2 ON t1.staff_id = t2.staff_id ORDER BY t2.date_complaint_raised LIMIT 1
|
Return the last name of the staff member who handled the complaint with the earliest date raised.
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT count(DISTINCT complaint_type_code) FROM complaints
|
How many distinct complaint type codes are there in the database?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT count(DISTINCT complaint_type_code) FROM complaints
|
Count the number of different complaint type codes.
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT address_line_1 , address_line_2 FROM customers WHERE email_address = "[email protected]"
|
Find the address line 1 and 2 of the customer with email "[email protected]".
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT address_line_1 , address_line_2 FROM customers WHERE email_address = "[email protected]"
|
What are lines 1 and 2 of the addressed of the customer with the email "[email protected]"?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT complaint_status_code , count(*) FROM complaints WHERE complaint_type_code = "Product Failure" GROUP BY complaint_status_code
|
Find the number of complaints with Product Failure type for each complaint status.
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT complaint_status_code , count(*) FROM complaints WHERE complaint_type_code = "Product Failure" GROUP BY complaint_status_code
|
Of complaints with the type code "Product Failure", how many had each different status code?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT t1.first_name FROM staff AS t1 JOIN complaints AS t2 ON t1.staff_id = t2.staff_id GROUP BY t2.staff_id ORDER BY count(*) LIMIT 5
|
What is first names of the top 5 staff who have handled the greatest number of complaints?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT t1.first_name FROM staff AS t1 JOIN complaints AS t2 ON t1.staff_id = t2.staff_id GROUP BY t2.staff_id ORDER BY count(*) LIMIT 5
|
Return the first names of the 5 staff members who have handled the most complaints.
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT state FROM customers GROUP BY state ORDER BY count(*) LIMIT 1
|
Which state has the most customers?
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
customer_complaints
|
SELECT state FROM customers GROUP BY state ORDER BY count(*) LIMIT 1
|
Give the state that has the most customers.
|
PRAGMA foreign_keys = ON;
CREATE TABLE `Staff` (
`staff_id` INTEGER PRIMARY KEY,
`gender` VARCHAR(1),
`first_name` VARCHAR(80),
`last_name` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_type_code` VARCHAR(20) NOT NULL,
`address_line_1` VARCHAR(80),
`address_line_2` VARCHAR(80),
`town_city` VARCHAR(80),
`state` VARCHAR(80),
`email_address` VARCHAR(255),
`phone_number` VARCHAR(80)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`product_category_code` VARCHAR(20) NOT NULL,
`date_product_first_available` DATETIME,
`date_product_discontinued` DATETIME,
`product_name` VARCHAR(80),
`product_description` VARCHAR(255),
`product_price` DECIMAL(19,4)
);
CREATE TABLE `Complaints` (
`complaint_id` INTEGER NOT NULL ,
`product_id` INTEGER NOT NULL,
`customer_id` INTEGER NOT NULL,
`complaint_outcome_code` VARCHAR(20) NOT NULL,
`complaint_status_code` VARCHAR(20) NOT NULL,
`complaint_type_code` VARCHAR(20) NOT NULL,
`date_complaint_raised` DATETIME,
`date_complaint_closed` DATETIME,
`staff_id` INTEGER NOT NULL ,
FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
INSERT INTO Staff (`staff_id`, `gender`, `first_name`, `last_name`, `email_address`, `phone_number`) VALUES (114, '0', 'Ward', 'Boehm', '[email protected]', '(379)INSERT INTO Customers (`customer_id`, `customer_type_code`, `address_line_1`, `address_line_2`, `town_city`, `state`, `email_address`, `phone_number`) VALUES (113, 'Good Credit Rating', '144 Legros Landing', 'Apt. 551', 'Maryamport', 'Kansas', '[email protected]', '06963347450')INSERT INTO Products (`product_id`, `parent_product_id`, `product_category_code`, `date_product_first_available`, `date_product_discontinued`, `product_name`, `product_description`, `product_price`) VALUES (117, 4, 'Food', '1988-09-29 17:54:50', '1987-12-20 13:46:16', 'Chocolate', 'Handmade chocolate', '2.8800')INSERT INTO Complaints (`complaint_id`, `product_id`, `customer_id`, `complaint_outcome_code`, `complaint_status_code`, `complaint_type_code`, `date_complaint_raised`, `date_complaint_closed`, `staff_id`) VALUES (1, 117, 120, 'OK', 'Closed', 'Product Failure', '2002-07-18 10:59:35', '1976-04-19 11:03:06', 114)
|
workshop_paper
|
SELECT count(*) FROM submission
|
How many submissions are there?
|
PRAGMA foreign_keys = ON;
CREATE TABLE "workshop" (
"Workshop_ID" int,
"Date" text,
"Venue" text,
"Name" text,
PRIMARY KEY ("Workshop_ID")
);
CREATE TABLE "submission" (
"Submission_ID" int,
"Scores" real,
"Author" text,
"College" text,
PRIMARY KEY ("Submission_ID")
);
CREATE TABLE "Acceptance" (
"Submission_ID" int,
"Workshop_ID" int,
"Result" text,
PRIMARY KEY ("Submission_ID","Workshop_ID"),
FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"),
FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID")
);
INSERT INTO "workshop" VALUES (1,"August 18, 2007","London UK","ABC 2007");
INSERT INTO "submission" VALUES ("1","72","Steve Niehaus","Notre Dame");
INSERT INTO "Acceptance" VALUES (2,5,"Accepted");
|
workshop_paper
|
SELECT count(*) FROM submission
|
Count the number of submissions.
|
PRAGMA foreign_keys = ON;
CREATE TABLE "workshop" (
"Workshop_ID" int,
"Date" text,
"Venue" text,
"Name" text,
PRIMARY KEY ("Workshop_ID")
);
CREATE TABLE "submission" (
"Submission_ID" int,
"Scores" real,
"Author" text,
"College" text,
PRIMARY KEY ("Submission_ID")
);
CREATE TABLE "Acceptance" (
"Submission_ID" int,
"Workshop_ID" int,
"Result" text,
PRIMARY KEY ("Submission_ID","Workshop_ID"),
FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"),
FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID")
);
INSERT INTO "workshop" VALUES (1,"August 18, 2007","London UK","ABC 2007");
INSERT INTO "submission" VALUES ("1","72","Steve Niehaus","Notre Dame");
INSERT INTO "Acceptance" VALUES (2,5,"Accepted");
|
workshop_paper
|
SELECT Author FROM submission ORDER BY Scores ASC
|
List the authors of submissions in ascending order of scores.
|
PRAGMA foreign_keys = ON;
CREATE TABLE "workshop" (
"Workshop_ID" int,
"Date" text,
"Venue" text,
"Name" text,
PRIMARY KEY ("Workshop_ID")
);
CREATE TABLE "submission" (
"Submission_ID" int,
"Scores" real,
"Author" text,
"College" text,
PRIMARY KEY ("Submission_ID")
);
CREATE TABLE "Acceptance" (
"Submission_ID" int,
"Workshop_ID" int,
"Result" text,
PRIMARY KEY ("Submission_ID","Workshop_ID"),
FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"),
FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID")
);
INSERT INTO "workshop" VALUES (1,"August 18, 2007","London UK","ABC 2007");
INSERT INTO "submission" VALUES ("1","72","Steve Niehaus","Notre Dame");
INSERT INTO "Acceptance" VALUES (2,5,"Accepted");
|
workshop_paper
|
SELECT Author FROM submission ORDER BY Scores ASC
|
Find the author for each submission and list them in ascending order of submission score.
|
PRAGMA foreign_keys = ON;
CREATE TABLE "workshop" (
"Workshop_ID" int,
"Date" text,
"Venue" text,
"Name" text,
PRIMARY KEY ("Workshop_ID")
);
CREATE TABLE "submission" (
"Submission_ID" int,
"Scores" real,
"Author" text,
"College" text,
PRIMARY KEY ("Submission_ID")
);
CREATE TABLE "Acceptance" (
"Submission_ID" int,
"Workshop_ID" int,
"Result" text,
PRIMARY KEY ("Submission_ID","Workshop_ID"),
FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"),
FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID")
);
INSERT INTO "workshop" VALUES (1,"August 18, 2007","London UK","ABC 2007");
INSERT INTO "submission" VALUES ("1","72","Steve Niehaus","Notre Dame");
INSERT INTO "Acceptance" VALUES (2,5,"Accepted");
|
workshop_paper
|
SELECT Author , College FROM submission
|
What are the authors of submissions and their colleges?
|
PRAGMA foreign_keys = ON;
CREATE TABLE "workshop" (
"Workshop_ID" int,
"Date" text,
"Venue" text,
"Name" text,
PRIMARY KEY ("Workshop_ID")
);
CREATE TABLE "submission" (
"Submission_ID" int,
"Scores" real,
"Author" text,
"College" text,
PRIMARY KEY ("Submission_ID")
);
CREATE TABLE "Acceptance" (
"Submission_ID" int,
"Workshop_ID" int,
"Result" text,
PRIMARY KEY ("Submission_ID","Workshop_ID"),
FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"),
FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID")
);
INSERT INTO "workshop" VALUES (1,"August 18, 2007","London UK","ABC 2007");
INSERT INTO "submission" VALUES ("1","72","Steve Niehaus","Notre Dame");
INSERT INTO "Acceptance" VALUES (2,5,"Accepted");
|
workshop_paper
|
SELECT Author , College FROM submission
|
For each submission, show the author and their affiliated college.
|
PRAGMA foreign_keys = ON;
CREATE TABLE "workshop" (
"Workshop_ID" int,
"Date" text,
"Venue" text,
"Name" text,
PRIMARY KEY ("Workshop_ID")
);
CREATE TABLE "submission" (
"Submission_ID" int,
"Scores" real,
"Author" text,
"College" text,
PRIMARY KEY ("Submission_ID")
);
CREATE TABLE "Acceptance" (
"Submission_ID" int,
"Workshop_ID" int,
"Result" text,
PRIMARY KEY ("Submission_ID","Workshop_ID"),
FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"),
FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID")
);
INSERT INTO "workshop" VALUES (1,"August 18, 2007","London UK","ABC 2007");
INSERT INTO "submission" VALUES ("1","72","Steve Niehaus","Notre Dame");
INSERT INTO "Acceptance" VALUES (2,5,"Accepted");
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.