db_id
stringclasses 40
values | question
stringlengths 22
185
| SQL
stringlengths 22
608
| db_schema_TC
stringclasses 280
values | db_schema_T
stringclasses 280
values | db_schema
stringclasses 40
values |
|---|---|---|---|---|---|
online_exams
|
What are the dates of the exams whose subject code contains the substring "data"? Return them in descending order of dates.
|
SELECT Exam_Date FROM Exams WHERE Subject_Code LIKE '%data%' ORDER BY Exam_Date DESC
|
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
|
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
What are the type of questions and their counts?
|
SELECT Type_of_Question_Code , COUNT(*) FROM Questions GROUP BY Type_of_Question_Code
|
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
|
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
For each question type, return its type code and its count of occurrence.
|
SELECT Type_of_Question_Code , COUNT(*) FROM Questions GROUP BY Type_of_Question_Code
|
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
|
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
What are the distinct student answer texts that received comments "Normal"?
|
SELECT DISTINCT Student_Answer_Text FROM Student_Answers WHERE Comments = "Normal"
|
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
List all the distinct student answer texts to which comments "Normal" were given?
|
SELECT DISTINCT Student_Answer_Text FROM Student_Answers WHERE Comments = "Normal"
|
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
How many different comments are there for student answers?
|
SELECT count(DISTINCT Comments) FROM Student_Answers
|
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
Count the number of different comments for student answers.
|
SELECT count(DISTINCT Comments) FROM Student_Answers
|
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
List all the student answer texts in descending order of count.
|
SELECT Student_Answer_Text FROM Student_Answers GROUP BY Student_Answer_Text ORDER BY COUNT(*) DESC
|
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
Sort the student answer texts in descending order of their frequency of occurrence.
|
SELECT Student_Answer_Text FROM Student_Answers GROUP BY Student_Answer_Text ORDER BY COUNT(*) DESC
|
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
Please show the first names of students and the dates of their answers.
|
SELECT T2.First_Name , T1.Date_of_Answer FROM Student_Answers AS T1 JOIN Students AS T2 ON T1.Student_ID = T2.Student_ID
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
For each student answer, find the first name of the student and the date of the answer.
|
SELECT T2.First_Name , T1.Date_of_Answer FROM Student_Answers AS T1 JOIN Students AS T2 ON T1.Student_ID = T2.Student_ID
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
Please show the email addresses of students and the dates of their answers in descending order of dates.
|
SELECT T2.Email_Adress , T1.Date_of_Answer FROM Student_Answers AS T1 JOIN Students AS T2 ON T1.Student_ID = T2.Student_ID ORDER BY T1.Date_of_Answer DESC
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
For each student answer, find the email address of the student and the date of the answer. Sort them in descending order of dates.
|
SELECT T2.Email_Adress , T1.Date_of_Answer FROM Student_Answers AS T1 JOIN Students AS T2 ON T1.Student_ID = T2.Student_ID ORDER BY T1.Date_of_Answer DESC
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
Please show the least common assessment for students.
|
SELECT Assessment FROM Student_Assessments GROUP BY Assessment ORDER BY COUNT(*) ASC LIMIT 1
|
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
Which assessment has the smallest frequency count?
|
SELECT Assessment FROM Student_Assessments GROUP BY Assessment ORDER BY COUNT(*) ASC LIMIT 1
|
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
Please show the first names of the students that have at least two answer records.
|
SELECT T2.First_Name FROM Student_Answers AS T1 JOIN Students AS T2 ON T1.Student_ID = T2.Student_ID GROUP BY T1.Student_ID HAVING COUNT(*) >= 2
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
Which students have 2 or more answer records? Give me their first names.
|
SELECT T2.First_Name FROM Student_Answers AS T1 JOIN Students AS T2 ON T1.Student_ID = T2.Student_ID GROUP BY T1.Student_ID HAVING COUNT(*) >= 2
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
What is the most common valid answer text?
|
SELECT Valid_Answer_Text FROM Valid_Answers GROUP BY Valid_Answer_Text ORDER BY COUNT(*) DESC LIMIT 1
|
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
|
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
Find the valid answer text that appeared most frequently.
|
SELECT Valid_Answer_Text FROM Valid_Answers GROUP BY Valid_Answer_Text ORDER BY COUNT(*) DESC LIMIT 1
|
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
|
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
List the last names of the students whose gender is not "M".
|
SELECT Last_Name FROM Students WHERE Gender_MFU != "M"
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
What are the last names of the students with gender other than "M"?
|
SELECT Last_Name FROM Students WHERE Gender_MFU != "M"
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
List each gender and the corresponding number of students.
|
SELECT Gender_MFU , COUNT(*) FROM Students GROUP BY Gender_MFU
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
For each gender, return the gender code and the number of students who identify as that gender.
|
SELECT Gender_MFU , COUNT(*) FROM Students GROUP BY Gender_MFU
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
List the last names of the students whose gender is "F" or "M".
|
SELECT Last_Name FROM Students WHERE Gender_MFU = "F" OR Gender_MFU = "M"
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
Which students identify their gender as "F" or "M"? Give me their last names.
|
SELECT Last_Name FROM Students WHERE Gender_MFU = "F" OR Gender_MFU = "M"
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
List the first names of the students who do not have any answers.
|
SELECT First_Name FROM Students WHERE Student_ID NOT IN (SELECT Student_ID FROM Student_Answers)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
Which students do not have any answers? Find their first names.
|
SELECT First_Name FROM Students WHERE Student_ID NOT IN (SELECT Student_ID FROM Student_Answers)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
Show the student answer texts that received both "Normal" and "Absent" as comments.
|
SELECT Student_Answer_Text FROM Student_Answers WHERE Comments = "Normal" INTERSECT SELECT Student_Answer_Text FROM Student_Answers WHERE Comments = "Absent"
|
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
Which student answer texts were given both "Normal" and "Absent" as comments?
|
SELECT Student_Answer_Text FROM Student_Answers WHERE Comments = "Normal" INTERSECT SELECT Student_Answer_Text FROM Student_Answers WHERE Comments = "Absent"
|
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
Show the types of questions that have at least three questions.
|
SELECT Type_of_Question_Code FROM Questions GROUP BY Type_of_Question_Code HAVING count(*) >= 3
|
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
|
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
Which types of questions have 3 or more questions? Return the questions type code.
|
SELECT Type_of_Question_Code FROM Questions GROUP BY Type_of_Question_Code HAVING count(*) >= 3
|
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
|
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
Show all information on students.
|
SELECT * FROM Students
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
online_exams
|
What is al the available information of each student?
|
SELECT * FROM Students
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
|
CREATE TABLE Students (
Student_ID INTEGER NOT NULL,
First_Name VARCHAR(255),
Middle_Name VARCHAR(255),
Last_Name VARCHAR(255),
Gender_MFU CHAR(1),
Student_Address VARCHAR(255),
Email_Adress VARCHAR(255),
Cell_Mobile_Phone VARCHAR(255),
Home_Phone VARCHAR(255),
PRIMARY KEY (Student_ID)
)
CREATE TABLE Questions (
Question_ID INTEGER NOT NULL,
Type_of_Question_Code VARCHAR(15) NOT NULL,
Question_Text VARCHAR(255),
PRIMARY KEY (Question_ID)
)
CREATE TABLE Exams (
Exam_ID INTEGER NOT NULL,
Subject_Code CHAR(15) NOT NULL,
Exam_Date DATETIME,
Exam_Name VARCHAR(255),
PRIMARY KEY (Exam_ID)
)
CREATE TABLE Questions_in_Exams (
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
PRIMARY KEY (Exam_ID, Question_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID),
FOREIGN KEY (Exam_ID) REFERENCES Exams (Exam_ID)
)
CREATE TABLE Valid_Answers (
Valid_Answer_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Valid_Answer_Text VARCHAR(255),
PRIMARY KEY (Valid_Answer_ID),
FOREIGN KEY (Question_ID) REFERENCES Questions (Question_ID)
)
CREATE TABLE Student_Answers (
Student_Answer_ID INTEGER NOT NULL,
Exam_ID INTEGER NOT NULL,
Question_ID INTEGER NOT NULL,
Student_ID INTEGER NOT NULL,
Date_of_Answer DATETIME,
Comments VARCHAR(255),
Satisfactory_YN VARCHAR(1),
Student_Answer_Text VARCHAR(255),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Student_ID) REFERENCES Students (Student_ID),
FOREIGN KEY (Exam_ID, Question_ID) REFERENCES Questions_in_Exams (Exam_ID,Question_ID)
)
CREATE TABLE Student_Assessments (
Student_Answer_ID VARCHAR(100) NOT NULL,
Valid_Answer_ID INTEGER NOT NULL,
Student_Answer_Text VARCHAR(255),
Satisfactory_YN CHAR(1),
Assessment VARCHAR(40),
PRIMARY KEY (Student_Answer_ID),
FOREIGN KEY (Valid_Answer_ID) REFERENCES Valid_Answers (Valid_Answer_ID)
)
|
customers_and_orders
|
How many addresses do we have?
|
SELECT count(*) FROM Addresses
|
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
|
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Count the number of addresses.
|
SELECT count(*) FROM Addresses
|
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
|
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
List all address ids and address details.
|
SELECT address_id , address_details FROM Addresses
|
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
|
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What are all the address ids and address details?
|
SELECT address_id , address_details FROM Addresses
|
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
|
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
How many products do we have?
|
SELECT count(*) FROM Products
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Count the number of products.
|
SELECT count(*) FROM Products
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Show all product ids, product type codes, and product name.
|
SELECT product_id , product_type_code , product_name FROM Products
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What are the ids, type codes, and names for all products?
|
SELECT product_id , product_type_code , product_name FROM Products
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What is the price for the product with name Monitor?
|
SELECT product_price FROM Products WHERE product_name = "Monitor"
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Give the price of the Monitor product.
|
SELECT product_price FROM Products WHERE product_name = "Monitor"
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Show the minimum, average, maximum price for all products.
|
SELECT min(product_price) , avg(product_price) , max(product_price) FROM Products
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What are the minimum, average, and maximum prices across all products?
|
SELECT min(product_price) , avg(product_price) , max(product_price) FROM Products
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What is the average price for products with type Clothes?
|
SELECT avg(product_price) FROM Products WHERE product_type_code = "Clothes"
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Return the average price of Clothes.
|
SELECT avg(product_price) FROM Products WHERE product_type_code = "Clothes"
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
How many hardware type products do we have?
|
SELECT count(*) FROM Products WHERE product_type_code = "Hardware"
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Count the number of products of the type Hardware.
|
SELECT count(*) FROM Products WHERE product_type_code = "Hardware"
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Show all product names with price higher than the average.
|
SELECT product_name FROM Products WHERE product_price > (SELECT avg(product_price) FROM Products)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What are the names of products that have a price above the average for all products.
|
SELECT product_name FROM Products WHERE product_price > (SELECT avg(product_price) FROM Products)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Show all hardware product names with price higher than the average price of hardware type products.
|
SELECT product_name FROM Products WHERE product_type_code = "Hardware" AND product_price > (SELECT avg(product_price) FROM Products WHERE product_type_code = "Hardware")
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What are the names of Hardware product with prices above the average price of Hardware products.
|
SELECT product_name FROM Products WHERE product_type_code = "Hardware" AND product_price > (SELECT avg(product_price) FROM Products WHERE product_type_code = "Hardware")
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What is the name of the most expensive product with type Clothes?
|
SELECT product_name FROM Products WHERE product_type_code = "Clothes" ORDER BY product_price DESC LIMIT 1
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Give the name of the most expensive Clothes product.
|
SELECT product_name FROM Products WHERE product_type_code = "Clothes" ORDER BY product_price DESC LIMIT 1
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What is the product id and product name for the cheapest Hardware type product?
|
SELECT product_id , product_name FROM Products WHERE product_type_code = "Hardware" ORDER BY product_price ASC LIMIT 1
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Give the id and name of the cheapest Hardware product.
|
SELECT product_id , product_name FROM Products WHERE product_type_code = "Hardware" ORDER BY product_price ASC LIMIT 1
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
List all product names in descending order of price.
|
SELECT product_name FROM Products ORDER BY product_price DESC
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What are the names of the products, sorted by descending price?
|
SELECT product_name FROM Products ORDER BY product_price DESC
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Show all hardware type products in ascending order of price.
|
SELECT product_name FROM Products WHERE product_type_code = "Hardware" ORDER BY product_price ASC
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What are the names of all Hardware products, sorted by price ascending?
|
SELECT product_name FROM Products WHERE product_type_code = "Hardware" ORDER BY product_price ASC
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
List all product type codes and the number of products in each type.
|
SELECT product_type_code , count(*) FROM Products GROUP BY product_type_code
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
How many products are there for each product type?
|
SELECT product_type_code , count(*) FROM Products GROUP BY product_type_code
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Show all product type codes and the average price for each type.
|
SELECT product_type_code , avg(product_price) FROM Products GROUP BY product_type_code
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What is the average price of products for each product type?
|
SELECT product_type_code , avg(product_price) FROM Products GROUP BY product_type_code
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What are the product type code with at least two products?
|
SELECT product_type_code FROM Products GROUP BY product_type_code HAVING count(*) >= 2
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Give the product type codes of product types that have two or more products.
|
SELECT product_type_code FROM Products GROUP BY product_type_code HAVING count(*) >= 2
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What is the product type code with most number of products?
|
SELECT product_type_code FROM Products GROUP BY product_type_code ORDER BY count(*) DESC LIMIT 1
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What is the most frequent product type code?
|
SELECT product_type_code FROM Products GROUP BY product_type_code ORDER BY count(*) DESC LIMIT 1
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
How many customers do we have?
|
SELECT count(*) FROM Customers
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Count the number of customers.
|
SELECT count(*) FROM Customers
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Show all customer ids and customer names.
|
SELECT customer_id , customer_name FROM Customers
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What are the ids and names of all customers?
|
SELECT customer_id , customer_name FROM Customers
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What is the customer address, customer phone, and customer email for Jeromy?
|
SELECT customer_address , customer_phone , customer_email FROM Customers WHERE customer_name = "Jeromy"
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Give the address, phone, and email for customers with the name Jeromy.
|
SELECT customer_address , customer_phone , customer_email FROM Customers WHERE customer_name = "Jeromy"
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Show all payment method codes and the number of customers in each code.
|
SELECT payment_method_code , count(*) FROM Customers GROUP BY payment_method_code
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
How many customers use each payment method?
|
SELECT payment_method_code , count(*) FROM Customers GROUP BY payment_method_code
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What is the payment method code used by most number of customers?
|
SELECT payment_method_code FROM Customers GROUP BY payment_method_code ORDER BY count(*) DESC LIMIT 1
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Give the code of the payment method that is most commonly used.
|
SELECT payment_method_code FROM Customers GROUP BY payment_method_code ORDER BY count(*) DESC LIMIT 1
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Show all customer names with the payment method code used by least number of customers.
|
SELECT customer_name FROM Customers WHERE payment_method_code = ( SELECT payment_method_code FROM Customers GROUP BY payment_method_code ORDER BY count(*) ASC LIMIT 1)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What are the names of customers who use the least common payment method?
|
SELECT customer_name FROM Customers WHERE payment_method_code = ( SELECT payment_method_code FROM Customers GROUP BY payment_method_code ORDER BY count(*) ASC LIMIT 1)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What is the payment method and customer number for customer named Jeromy?
|
SELECT payment_method_code , customer_number FROM Customers WHERE customer_name = "Jeromy"
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Give the payment method code and customer number corresponding to the customer named Jeromy.
|
SELECT payment_method_code , customer_number FROM Customers WHERE customer_name = "Jeromy"
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What are the distinct payment methods used by customers?
|
SELECT DISTINCT payment_method_code FROM Customers
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Give the different payment method codes that customers use.
|
SELECT DISTINCT payment_method_code FROM Customers
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Show the id and the product type for all products, order by product name.
|
SELECT product_id , product_type_code FROM Products ORDER BY product_name
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What are the ids and product types for all products, sorted alphabetically by product name?
|
SELECT product_id , product_type_code FROM Products ORDER BY product_name
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What is the product type with least number of products?
|
SELECT product_type_code FROM Products GROUP BY product_type_code ORDER BY count(*) ASC LIMIT 1
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What is the code of the product type that is least common?
|
SELECT product_type_code FROM Products GROUP BY product_type_code ORDER BY count(*) ASC LIMIT 1
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
How many customer orders do we have?
|
SELECT count(*) FROM Customer_orders
|
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Count the number of customer orders.
|
SELECT count(*) FROM Customer_orders
|
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Show the order ids, order dates, and order status codes for all orders by customer Jeromy.
|
SELECT order_id , order_date , order_status_code FROM Customer_orders AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE T2.customer_name = "Jeromy"
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What were the ids, dates, and status codes for orders made by Jeromy?
|
SELECT order_id , order_date , order_status_code FROM Customer_orders AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE T2.customer_name = "Jeromy"
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Show all customer names, ids and the number of orders by each customer.
|
SELECT T2.customer_name , T1.customer_id , count(*) FROM Customer_orders AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What are the names, ids, and number of orders made for each customer?
|
SELECT T2.customer_name , T1.customer_id , count(*) FROM Customer_orders AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What is the customer id, name, phone, and email for the customer with most orders?
|
SELECT T1.customer_id , T2.customer_name , T2.customer_phone , T2.customer_email FROM Customer_orders AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Give the id, name, phone, and email corresponding to the customer who made the most orders.
|
SELECT T1.customer_id , T2.customer_name , T2.customer_phone , T2.customer_email FROM Customer_orders AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
Show all order status and the number of orders in each status.
|
SELECT order_status_code , count(*) FROM Customer_orders GROUP BY order_status_code
|
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
How many orders have each order status code?
|
SELECT order_status_code , count(*) FROM Customer_orders GROUP BY order_status_code
|
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
customers_and_orders
|
What is the order status code that is most common?
|
SELECT order_status_code FROM Customer_orders GROUP BY order_status_code ORDER BY count(*) DESC LIMIT 1
|
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
|
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`product_type_code` VARCHAR(15),
`product_name` VARCHAR(80),
`product_price` DOUBLE NULL
)
CREATE TABLE `Addresses` (
`address_id` INTEGER PRIMARY KEY,
`address_details` VARCHAR(255)
)
CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`address_id` INTEGER NOT NULL,
`payment_method_code` VARCHAR(15),
`customer_number` VARCHAR(20),
`customer_name` VARCHAR(80),
`customer_address` VARCHAR(255),
`customer_phone` VARCHAR(80),
`customer_email` VARCHAR(80)
)
CREATE TABLE `Customer_Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`order_date` DATETIME NOT NULL,
`order_status_code` VARCHAR(15),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
)
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER NOT NULL ,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`order_quantity` VARCHAR(80),
FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.