db_id
stringclasses 127
values | query
stringlengths 20
523
| question
stringlengths 16
224
| schema
stringclasses 127
values |
---|---|---|---|
performance_attendance | SELECT avg(Attendance) FROM performance | What is the average number of attendees for performances? | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
);
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
);
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
);
INSERT INTO "member" VALUES ("1","Wilfredo Ruiz","Uruguay","Prime Violin");
INSERT INTO "performance" VALUES (1,"February 2","Boston Bruins","TD Garden","165");
INSERT INTO "member_attendance" VALUES (11,3,2); |
performance_attendance | SELECT Date FROM performance ORDER BY Attendance DESC LIMIT 1 | What is the date of the performance with the highest number of attendees? | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
);
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
);
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
);
INSERT INTO "member" VALUES ("1","Wilfredo Ruiz","Uruguay","Prime Violin");
INSERT INTO "performance" VALUES (1,"February 2","Boston Bruins","TD Garden","165");
INSERT INTO "member_attendance" VALUES (11,3,2); |
performance_attendance | SELECT LOCATION , COUNT(*) FROM performance GROUP BY LOCATION | Show different locations and the number of performances at each location. | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
);
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
);
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
);
INSERT INTO "member" VALUES ("1","Wilfredo Ruiz","Uruguay","Prime Violin");
INSERT INTO "performance" VALUES (1,"February 2","Boston Bruins","TD Garden","165");
INSERT INTO "member_attendance" VALUES (11,3,2); |
performance_attendance | SELECT LOCATION FROM performance GROUP BY LOCATION ORDER BY COUNT(*) DESC LIMIT 1 | Show the most common location of performances. | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
);
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
);
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
);
INSERT INTO "member" VALUES ("1","Wilfredo Ruiz","Uruguay","Prime Violin");
INSERT INTO "performance" VALUES (1,"February 2","Boston Bruins","TD Garden","165");
INSERT INTO "member_attendance" VALUES (11,3,2); |
performance_attendance | SELECT LOCATION FROM performance GROUP BY LOCATION HAVING COUNT(*) >= 2 | Show the locations that have at least two performances. | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
);
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
);
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
);
INSERT INTO "member" VALUES ("1","Wilfredo Ruiz","Uruguay","Prime Violin");
INSERT INTO "performance" VALUES (1,"February 2","Boston Bruins","TD Garden","165");
INSERT INTO "member_attendance" VALUES (11,3,2); |
performance_attendance | SELECT LOCATION FROM performance WHERE Attendance > 2000 INTERSECT SELECT LOCATION FROM performance WHERE Attendance < 1000 | Show the locations that have both performances with more than 2000 attendees and performances with less than 1000 attendees. | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
);
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
);
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
);
INSERT INTO "member" VALUES ("1","Wilfredo Ruiz","Uruguay","Prime Violin");
INSERT INTO "performance" VALUES (1,"February 2","Boston Bruins","TD Garden","165");
INSERT INTO "member_attendance" VALUES (11,3,2); |
performance_attendance | SELECT T2.Name , T3.Location FROM member_attendance AS T1 JOIN member AS T2 ON T1.Member_ID = T2.Member_ID JOIN performance AS T3 ON T1.Performance_ID = T3.Performance_ID | Show the names of members and the location of the performances they attended. | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
);
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
);
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
);
INSERT INTO "member" VALUES ("1","Wilfredo Ruiz","Uruguay","Prime Violin");
INSERT INTO "performance" VALUES (1,"February 2","Boston Bruins","TD Garden","165");
INSERT INTO "member_attendance" VALUES (11,3,2); |
performance_attendance | SELECT T2.Name , T3.Location FROM member_attendance AS T1 JOIN member AS T2 ON T1.Member_ID = T2.Member_ID JOIN performance AS T3 ON T1.Performance_ID = T3.Performance_ID ORDER BY T2.Name ASC | Show the names of members and the location of performances they attended in ascending alphabetical order of their names. | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
);
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
);
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
);
INSERT INTO "member" VALUES ("1","Wilfredo Ruiz","Uruguay","Prime Violin");
INSERT INTO "performance" VALUES (1,"February 2","Boston Bruins","TD Garden","165");
INSERT INTO "member_attendance" VALUES (11,3,2); |
performance_attendance | SELECT T3.Date FROM member_attendance AS T1 JOIN member AS T2 ON T1.Member_ID = T2.Member_ID JOIN performance AS T3 ON T1.Performance_ID = T3.Performance_ID WHERE T2.Role = "Violin" | Show the dates of performances with attending members whose roles are "Violin". | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
);
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
);
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
);
INSERT INTO "member" VALUES ("1","Wilfredo Ruiz","Uruguay","Prime Violin");
INSERT INTO "performance" VALUES (1,"February 2","Boston Bruins","TD Garden","165");
INSERT INTO "member_attendance" VALUES (11,3,2); |
performance_attendance | SELECT T2.Name , T3.Date FROM member_attendance AS T1 JOIN member AS T2 ON T1.Member_ID = T2.Member_ID JOIN performance AS T3 ON T1.Performance_ID = T3.Performance_ID ORDER BY T3.Attendance DESC | Show the names of members and the dates of performances they attended in descending order of attendance of the performances. | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
);
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
);
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
);
INSERT INTO "member" VALUES ("1","Wilfredo Ruiz","Uruguay","Prime Violin");
INSERT INTO "performance" VALUES (1,"February 2","Boston Bruins","TD Garden","165");
INSERT INTO "member_attendance" VALUES (11,3,2); |
performance_attendance | SELECT Name FROM member WHERE Member_ID NOT IN (SELECT Member_ID FROM member_attendance) | List the names of members who did not attend any performance. | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
);
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
);
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
);
INSERT INTO "member" VALUES ("1","Wilfredo Ruiz","Uruguay","Prime Violin");
INSERT INTO "performance" VALUES (1,"February 2","Boston Bruins","TD Garden","165");
INSERT INTO "member_attendance" VALUES (11,3,2); |
debate | SELECT count(*) FROM debate | How many debates are there? | CREATE TABLE "people" (
"People_ID" int,
"District" text,
"Name" text,
"Party" text,
"Age" int,
PRIMARY KEY ("People_ID")
);
CREATE TABLE "debate" (
"Debate_ID" int,
"Date" text,
"Venue" text,
"Num_of_Audience" int,
PRIMARY KEY ("Debate_ID")
);
CREATE TABLE "debate_people" (
"Debate_ID" int,
"Affirmative" int,
"Negative" int,
"If_Affirmative_Win" bool,
PRIMARY KEY ("Debate_ID","Affirmative","Negative"),
FOREIGN KEY ("Debate_ID") REFERENCES `debate`("Debate_ID"),
FOREIGN KEY ("Affirmative") REFERENCES `people`("People_ID"),
FOREIGN KEY ("Negative") REFERENCES `people`("People_ID")
);
INSERT INTO "people" VALUES (1,"New York 1","Luther C. Carter","Republican",35);
INSERT INTO "debate" VALUES (1,"October 21, 2011","Manama , Bahrain",342);
INSERT INTO "debate_people" VALUES (1,1,10,"F"); |
debate | SELECT Venue FROM debate ORDER BY Num_of_Audience ASC | List the venues of debates in ascending order of the number of audience. | CREATE TABLE "people" (
"People_ID" int,
"District" text,
"Name" text,
"Party" text,
"Age" int,
PRIMARY KEY ("People_ID")
);
CREATE TABLE "debate" (
"Debate_ID" int,
"Date" text,
"Venue" text,
"Num_of_Audience" int,
PRIMARY KEY ("Debate_ID")
);
CREATE TABLE "debate_people" (
"Debate_ID" int,
"Affirmative" int,
"Negative" int,
"If_Affirmative_Win" bool,
PRIMARY KEY ("Debate_ID","Affirmative","Negative"),
FOREIGN KEY ("Debate_ID") REFERENCES `debate`("Debate_ID"),
FOREIGN KEY ("Affirmative") REFERENCES `people`("People_ID"),
FOREIGN KEY ("Negative") REFERENCES `people`("People_ID")
);
INSERT INTO "people" VALUES (1,"New York 1","Luther C. Carter","Republican",35);
INSERT INTO "debate" VALUES (1,"October 21, 2011","Manama , Bahrain",342);
INSERT INTO "debate_people" VALUES (1,1,10,"F"); |
debate | SELECT Date , Venue FROM debate | What are the date and venue of each debate? | CREATE TABLE "people" (
"People_ID" int,
"District" text,
"Name" text,
"Party" text,
"Age" int,
PRIMARY KEY ("People_ID")
);
CREATE TABLE "debate" (
"Debate_ID" int,
"Date" text,
"Venue" text,
"Num_of_Audience" int,
PRIMARY KEY ("Debate_ID")
);
CREATE TABLE "debate_people" (
"Debate_ID" int,
"Affirmative" int,
"Negative" int,
"If_Affirmative_Win" bool,
PRIMARY KEY ("Debate_ID","Affirmative","Negative"),
FOREIGN KEY ("Debate_ID") REFERENCES `debate`("Debate_ID"),
FOREIGN KEY ("Affirmative") REFERENCES `people`("People_ID"),
FOREIGN KEY ("Negative") REFERENCES `people`("People_ID")
);
INSERT INTO "people" VALUES (1,"New York 1","Luther C. Carter","Republican",35);
INSERT INTO "debate" VALUES (1,"October 21, 2011","Manama , Bahrain",342);
INSERT INTO "debate_people" VALUES (1,1,10,"F"); |
debate | SELECT Date FROM debate WHERE Num_of_Audience > 150 | List the dates of debates with number of audience bigger than 150 | CREATE TABLE "people" (
"People_ID" int,
"District" text,
"Name" text,
"Party" text,
"Age" int,
PRIMARY KEY ("People_ID")
);
CREATE TABLE "debate" (
"Debate_ID" int,
"Date" text,
"Venue" text,
"Num_of_Audience" int,
PRIMARY KEY ("Debate_ID")
);
CREATE TABLE "debate_people" (
"Debate_ID" int,
"Affirmative" int,
"Negative" int,
"If_Affirmative_Win" bool,
PRIMARY KEY ("Debate_ID","Affirmative","Negative"),
FOREIGN KEY ("Debate_ID") REFERENCES `debate`("Debate_ID"),
FOREIGN KEY ("Affirmative") REFERENCES `people`("People_ID"),
FOREIGN KEY ("Negative") REFERENCES `people`("People_ID")
);
INSERT INTO "people" VALUES (1,"New York 1","Luther C. Carter","Republican",35);
INSERT INTO "debate" VALUES (1,"October 21, 2011","Manama , Bahrain",342);
INSERT INTO "debate_people" VALUES (1,1,10,"F"); |
debate | SELECT Name FROM people WHERE Age = 35 OR Age = 36 | Show the names of people aged either 35 or 36. | CREATE TABLE "people" (
"People_ID" int,
"District" text,
"Name" text,
"Party" text,
"Age" int,
PRIMARY KEY ("People_ID")
);
CREATE TABLE "debate" (
"Debate_ID" int,
"Date" text,
"Venue" text,
"Num_of_Audience" int,
PRIMARY KEY ("Debate_ID")
);
CREATE TABLE "debate_people" (
"Debate_ID" int,
"Affirmative" int,
"Negative" int,
"If_Affirmative_Win" bool,
PRIMARY KEY ("Debate_ID","Affirmative","Negative"),
FOREIGN KEY ("Debate_ID") REFERENCES `debate`("Debate_ID"),
FOREIGN KEY ("Affirmative") REFERENCES `people`("People_ID"),
FOREIGN KEY ("Negative") REFERENCES `people`("People_ID")
);
INSERT INTO "people" VALUES (1,"New York 1","Luther C. Carter","Republican",35);
INSERT INTO "debate" VALUES (1,"October 21, 2011","Manama , Bahrain",342);
INSERT INTO "debate_people" VALUES (1,1,10,"F"); |
debate | SELECT Party FROM people ORDER BY Age ASC LIMIT 1 | What is the party of the youngest people? | CREATE TABLE "people" (
"People_ID" int,
"District" text,
"Name" text,
"Party" text,
"Age" int,
PRIMARY KEY ("People_ID")
);
CREATE TABLE "debate" (
"Debate_ID" int,
"Date" text,
"Venue" text,
"Num_of_Audience" int,
PRIMARY KEY ("Debate_ID")
);
CREATE TABLE "debate_people" (
"Debate_ID" int,
"Affirmative" int,
"Negative" int,
"If_Affirmative_Win" bool,
PRIMARY KEY ("Debate_ID","Affirmative","Negative"),
FOREIGN KEY ("Debate_ID") REFERENCES `debate`("Debate_ID"),
FOREIGN KEY ("Affirmative") REFERENCES `people`("People_ID"),
FOREIGN KEY ("Negative") REFERENCES `people`("People_ID")
);
INSERT INTO "people" VALUES (1,"New York 1","Luther C. Carter","Republican",35);
INSERT INTO "debate" VALUES (1,"October 21, 2011","Manama , Bahrain",342);
INSERT INTO "debate_people" VALUES (1,1,10,"F"); |
debate | SELECT Party , COUNT(*) FROM people GROUP BY Party | Show different parties of people along with the number of people in each party. | CREATE TABLE "people" (
"People_ID" int,
"District" text,
"Name" text,
"Party" text,
"Age" int,
PRIMARY KEY ("People_ID")
);
CREATE TABLE "debate" (
"Debate_ID" int,
"Date" text,
"Venue" text,
"Num_of_Audience" int,
PRIMARY KEY ("Debate_ID")
);
CREATE TABLE "debate_people" (
"Debate_ID" int,
"Affirmative" int,
"Negative" int,
"If_Affirmative_Win" bool,
PRIMARY KEY ("Debate_ID","Affirmative","Negative"),
FOREIGN KEY ("Debate_ID") REFERENCES `debate`("Debate_ID"),
FOREIGN KEY ("Affirmative") REFERENCES `people`("People_ID"),
FOREIGN KEY ("Negative") REFERENCES `people`("People_ID")
);
INSERT INTO "people" VALUES (1,"New York 1","Luther C. Carter","Republican",35);
INSERT INTO "debate" VALUES (1,"October 21, 2011","Manama , Bahrain",342);
INSERT INTO "debate_people" VALUES (1,1,10,"F"); |
debate | SELECT Party FROM people GROUP BY Party ORDER BY COUNT(*) DESC LIMIT 1 | Show the party that has the most people. | CREATE TABLE "people" (
"People_ID" int,
"District" text,
"Name" text,
"Party" text,
"Age" int,
PRIMARY KEY ("People_ID")
);
CREATE TABLE "debate" (
"Debate_ID" int,
"Date" text,
"Venue" text,
"Num_of_Audience" int,
PRIMARY KEY ("Debate_ID")
);
CREATE TABLE "debate_people" (
"Debate_ID" int,
"Affirmative" int,
"Negative" int,
"If_Affirmative_Win" bool,
PRIMARY KEY ("Debate_ID","Affirmative","Negative"),
FOREIGN KEY ("Debate_ID") REFERENCES `debate`("Debate_ID"),
FOREIGN KEY ("Affirmative") REFERENCES `people`("People_ID"),
FOREIGN KEY ("Negative") REFERENCES `people`("People_ID")
);
INSERT INTO "people" VALUES (1,"New York 1","Luther C. Carter","Republican",35);
INSERT INTO "debate" VALUES (1,"October 21, 2011","Manama , Bahrain",342);
INSERT INTO "debate_people" VALUES (1,1,10,"F"); |
debate | SELECT DISTINCT Venue FROM debate | Show the distinct venues of debates | CREATE TABLE "people" (
"People_ID" int,
"District" text,
"Name" text,
"Party" text,
"Age" int,
PRIMARY KEY ("People_ID")
);
CREATE TABLE "debate" (
"Debate_ID" int,
"Date" text,
"Venue" text,
"Num_of_Audience" int,
PRIMARY KEY ("Debate_ID")
);
CREATE TABLE "debate_people" (
"Debate_ID" int,
"Affirmative" int,
"Negative" int,
"If_Affirmative_Win" bool,
PRIMARY KEY ("Debate_ID","Affirmative","Negative"),
FOREIGN KEY ("Debate_ID") REFERENCES `debate`("Debate_ID"),
FOREIGN KEY ("Affirmative") REFERENCES `people`("People_ID"),
FOREIGN KEY ("Negative") REFERENCES `people`("People_ID")
);
INSERT INTO "people" VALUES (1,"New York 1","Luther C. Carter","Republican",35);
INSERT INTO "debate" VALUES (1,"October 21, 2011","Manama , Bahrain",342);
INSERT INTO "debate_people" VALUES (1,1,10,"F"); |
debate | SELECT T3.Name , T2.Date , T2.Venue FROM debate_people AS T1 JOIN debate AS T2 ON T1.Debate_ID = T2.Debate_ID JOIN people AS T3 ON T1.Affirmative = T3.People_ID | Show the names of people, and dates and venues of debates they are on the affirmative side. | CREATE TABLE "people" (
"People_ID" int,
"District" text,
"Name" text,
"Party" text,
"Age" int,
PRIMARY KEY ("People_ID")
);
CREATE TABLE "debate" (
"Debate_ID" int,
"Date" text,
"Venue" text,
"Num_of_Audience" int,
PRIMARY KEY ("Debate_ID")
);
CREATE TABLE "debate_people" (
"Debate_ID" int,
"Affirmative" int,
"Negative" int,
"If_Affirmative_Win" bool,
PRIMARY KEY ("Debate_ID","Affirmative","Negative"),
FOREIGN KEY ("Debate_ID") REFERENCES `debate`("Debate_ID"),
FOREIGN KEY ("Affirmative") REFERENCES `people`("People_ID"),
FOREIGN KEY ("Negative") REFERENCES `people`("People_ID")
);
INSERT INTO "people" VALUES (1,"New York 1","Luther C. Carter","Republican",35);
INSERT INTO "debate" VALUES (1,"October 21, 2011","Manama , Bahrain",342);
INSERT INTO "debate_people" VALUES (1,1,10,"F"); |
debate | SELECT T3.Name , T2.Date , T2.Venue FROM debate_people AS T1 JOIN debate AS T2 ON T1.Debate_ID = T2.Debate_ID JOIN people AS T3 ON T1.Negative = T3.People_ID ORDER BY T3.Name ASC | Show the names of people, and dates and venues of debates they are on the negative side, ordered in ascending alphabetical order of name. | CREATE TABLE "people" (
"People_ID" int,
"District" text,
"Name" text,
"Party" text,
"Age" int,
PRIMARY KEY ("People_ID")
);
CREATE TABLE "debate" (
"Debate_ID" int,
"Date" text,
"Venue" text,
"Num_of_Audience" int,
PRIMARY KEY ("Debate_ID")
);
CREATE TABLE "debate_people" (
"Debate_ID" int,
"Affirmative" int,
"Negative" int,
"If_Affirmative_Win" bool,
PRIMARY KEY ("Debate_ID","Affirmative","Negative"),
FOREIGN KEY ("Debate_ID") REFERENCES `debate`("Debate_ID"),
FOREIGN KEY ("Affirmative") REFERENCES `people`("People_ID"),
FOREIGN KEY ("Negative") REFERENCES `people`("People_ID")
);
INSERT INTO "people" VALUES (1,"New York 1","Luther C. Carter","Republican",35);
INSERT INTO "debate" VALUES (1,"October 21, 2011","Manama , Bahrain",342);
INSERT INTO "debate_people" VALUES (1,1,10,"F"); |
debate | SELECT T3.Name FROM debate_people AS T1 JOIN debate AS T2 ON T1.Debate_ID = T2.Debate_ID JOIN people AS T3 ON T1.Affirmative = T3.People_ID WHERE T2.Num_of_Audience > 200 | Show the names of people that are on affirmative side of debates with number of audience bigger than 200. | CREATE TABLE "people" (
"People_ID" int,
"District" text,
"Name" text,
"Party" text,
"Age" int,
PRIMARY KEY ("People_ID")
);
CREATE TABLE "debate" (
"Debate_ID" int,
"Date" text,
"Venue" text,
"Num_of_Audience" int,
PRIMARY KEY ("Debate_ID")
);
CREATE TABLE "debate_people" (
"Debate_ID" int,
"Affirmative" int,
"Negative" int,
"If_Affirmative_Win" bool,
PRIMARY KEY ("Debate_ID","Affirmative","Negative"),
FOREIGN KEY ("Debate_ID") REFERENCES `debate`("Debate_ID"),
FOREIGN KEY ("Affirmative") REFERENCES `people`("People_ID"),
FOREIGN KEY ("Negative") REFERENCES `people`("People_ID")
);
INSERT INTO "people" VALUES (1,"New York 1","Luther C. Carter","Republican",35);
INSERT INTO "debate" VALUES (1,"October 21, 2011","Manama , Bahrain",342);
INSERT INTO "debate_people" VALUES (1,1,10,"F"); |
debate | SELECT T2.Name , COUNT(*) FROM debate_people AS T1 JOIN people AS T2 ON T1.Affirmative = T2.People_ID GROUP BY T2.Name | Show the names of people and the number of times they have been on the affirmative side of debates. | CREATE TABLE "people" (
"People_ID" int,
"District" text,
"Name" text,
"Party" text,
"Age" int,
PRIMARY KEY ("People_ID")
);
CREATE TABLE "debate" (
"Debate_ID" int,
"Date" text,
"Venue" text,
"Num_of_Audience" int,
PRIMARY KEY ("Debate_ID")
);
CREATE TABLE "debate_people" (
"Debate_ID" int,
"Affirmative" int,
"Negative" int,
"If_Affirmative_Win" bool,
PRIMARY KEY ("Debate_ID","Affirmative","Negative"),
FOREIGN KEY ("Debate_ID") REFERENCES `debate`("Debate_ID"),
FOREIGN KEY ("Affirmative") REFERENCES `people`("People_ID"),
FOREIGN KEY ("Negative") REFERENCES `people`("People_ID")
);
INSERT INTO "people" VALUES (1,"New York 1","Luther C. Carter","Republican",35);
INSERT INTO "debate" VALUES (1,"October 21, 2011","Manama , Bahrain",342);
INSERT INTO "debate_people" VALUES (1,1,10,"F"); |
debate | SELECT T2.Name FROM debate_people AS T1 JOIN people AS T2 ON T1.Negative = T2.People_ID GROUP BY T2.Name HAVING COUNT(*) >= 2 | Show the names of people who have been on the negative side of debates at least twice. | CREATE TABLE "people" (
"People_ID" int,
"District" text,
"Name" text,
"Party" text,
"Age" int,
PRIMARY KEY ("People_ID")
);
CREATE TABLE "debate" (
"Debate_ID" int,
"Date" text,
"Venue" text,
"Num_of_Audience" int,
PRIMARY KEY ("Debate_ID")
);
CREATE TABLE "debate_people" (
"Debate_ID" int,
"Affirmative" int,
"Negative" int,
"If_Affirmative_Win" bool,
PRIMARY KEY ("Debate_ID","Affirmative","Negative"),
FOREIGN KEY ("Debate_ID") REFERENCES `debate`("Debate_ID"),
FOREIGN KEY ("Affirmative") REFERENCES `people`("People_ID"),
FOREIGN KEY ("Negative") REFERENCES `people`("People_ID")
);
INSERT INTO "people" VALUES (1,"New York 1","Luther C. Carter","Republican",35);
INSERT INTO "debate" VALUES (1,"October 21, 2011","Manama , Bahrain",342);
INSERT INTO "debate_people" VALUES (1,1,10,"F"); |
debate | SELECT Name FROM people WHERE People_id NOT IN (SELECT Affirmative FROM debate_people) | List the names of people that have not been on the affirmative side of debates. | CREATE TABLE "people" (
"People_ID" int,
"District" text,
"Name" text,
"Party" text,
"Age" int,
PRIMARY KEY ("People_ID")
);
CREATE TABLE "debate" (
"Debate_ID" int,
"Date" text,
"Venue" text,
"Num_of_Audience" int,
PRIMARY KEY ("Debate_ID")
);
CREATE TABLE "debate_people" (
"Debate_ID" int,
"Affirmative" int,
"Negative" int,
"If_Affirmative_Win" bool,
PRIMARY KEY ("Debate_ID","Affirmative","Negative"),
FOREIGN KEY ("Debate_ID") REFERENCES `debate`("Debate_ID"),
FOREIGN KEY ("Affirmative") REFERENCES `people`("People_ID"),
FOREIGN KEY ("Negative") REFERENCES `people`("People_ID")
);
INSERT INTO "people" VALUES (1,"New York 1","Luther C. Carter","Republican",35);
INSERT INTO "debate" VALUES (1,"October 21, 2011","Manama , Bahrain",342);
INSERT INTO "debate_people" VALUES (1,1,10,"F"); |
insurance_and_eClaims | SELECT customer_details FROM customers ORDER BY customer_details | List the names of all the customers in alphabetical order. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT customer_details FROM customers ORDER BY customer_details | Sort the customer names in alphabetical order. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT policy_type_code FROM policies AS t1 JOIN customers AS t2 ON t1.customer_id = t2.customer_id WHERE t2.customer_details = "Dayana Robel" | Find all the policy type codes associated with the customer "Dayana Robel" | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT policy_type_code FROM policies AS t1 JOIN customers AS t2 ON t1.customer_id = t2.customer_id WHERE t2.customer_details = "Dayana Robel" | What are the type codes of the policies used by the customer "Dayana Robel"? | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT policy_type_code FROM policies GROUP BY policy_type_code ORDER BY count(*) DESC LIMIT 1 | Which type of policy is most frequently used? Give me the policy type code. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT policy_type_code FROM policies GROUP BY policy_type_code ORDER BY count(*) DESC LIMIT 1 | Find the type code of the most frequently used policy. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT policy_type_code FROM policies GROUP BY policy_type_code HAVING count(*) > 2 | Find all the policy types that are used by more than 2 customers. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT policy_type_code FROM policies GROUP BY policy_type_code HAVING count(*) > 2 | Which types of policy are chosen by more than 2 customers? Give me the policy type codes. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT sum(amount_piad) , avg(amount_piad) FROM claim_headers | Find the total and average amount paid in claim headers. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT sum(amount_piad) , avg(amount_piad) FROM claim_headers | What are the total amount and average amount paid in claim headers? | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT sum(t1.amount_claimed) FROM claim_headers AS t1 JOIN claims_documents AS t2 ON t1.claim_header_id = t2.claim_id WHERE t2.created_date = (SELECT created_date FROM claims_documents ORDER BY created_date LIMIT 1) | Find the total amount claimed in the most recently created document. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT sum(t1.amount_claimed) FROM claim_headers AS t1 JOIN claims_documents AS t2 ON t1.claim_header_id = t2.claim_id WHERE t2.created_date = (SELECT created_date FROM claims_documents ORDER BY created_date LIMIT 1) | How much amount in total were claimed in the most recently created document? | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT t3.customer_details FROM claim_headers AS t1 JOIN policies AS t2 ON t1.policy_id = t2.policy_id JOIN customers AS t3 ON t2.customer_id = t3.customer_id WHERE t1.amount_claimed = (SELECT max(amount_claimed) FROM claim_headers) | What is the name of the customer who has made the largest amount of claim in a single claim? | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT t3.customer_details FROM claim_headers AS t1 JOIN policies AS t2 ON t1.policy_id = t2.policy_id JOIN customers AS t3 ON t2.customer_id = t3.customer_id WHERE t1.amount_claimed = (SELECT max(amount_claimed) FROM claim_headers) | Which customer made the largest amount of claim in a single claim? Return the customer details. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT t3.customer_details FROM claim_headers AS t1 JOIN policies AS t2 ON t1.policy_id = t2.policy_id JOIN customers AS t3 ON t2.customer_id = t3.customer_id WHERE t1.amount_piad = (SELECT min(amount_piad) FROM claim_headers) | What is the name of the customer who has made the minimum amount of payment in one claim? | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT t3.customer_details FROM claim_headers AS t1 JOIN policies AS t2 ON t1.policy_id = t2.policy_id JOIN customers AS t3 ON t2.customer_id = t3.customer_id WHERE t1.amount_piad = (SELECT min(amount_piad) FROM claim_headers) | Which customer made the smallest amount of claim in one claim? Return the customer details. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT customer_details FROM customers EXCEPT SELECT t2.customer_details FROM policies AS t1 JOIN customers AS t2 ON t1.customer_id = t2.customer_id | Find the names of customers who have no policies associated. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT customer_details FROM customers EXCEPT SELECT t2.customer_details FROM policies AS t1 JOIN customers AS t2 ON t1.customer_id = t2.customer_id | What are the names of customers who do not have any policies? | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT count(*) FROM claims_processing_stages | How many claim processing stages are there in total? | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT count(*) FROM claims_processing_stages | Find the number of distinct stages in claim processing. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT t2.claim_status_name FROM claims_processing AS t1 JOIN claims_processing_stages AS t2 ON t1.claim_stage_id = t2.claim_stage_id GROUP BY t1.claim_stage_id ORDER BY count(*) DESC LIMIT 1 | What is the name of the claim processing stage that most of the claims are on? | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT t2.claim_status_name FROM claims_processing AS t1 JOIN claims_processing_stages AS t2 ON t1.claim_stage_id = t2.claim_stage_id GROUP BY t1.claim_stage_id ORDER BY count(*) DESC LIMIT 1 | Which claim processing stage has the most claims? Show the claim status name. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT customer_details FROM customers WHERE customer_details LIKE "%Diana%" | Find the names of customers whose name contains "Diana". | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT customer_details FROM customers WHERE customer_details LIKE "%Diana%" | Which customers have the substring "Diana" in their names? Return the customer details. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT DISTINCT t2.customer_details FROM policies AS t1 JOIN customers AS t2 ON t1.customer_id = t2.customer_id WHERE t1.policy_type_code = "Deputy" | Find the names of the customers who have an deputy policy. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT DISTINCT t2.customer_details FROM policies AS t1 JOIN customers AS t2 ON t1.customer_id = t2.customer_id WHERE t1.policy_type_code = "Deputy" | Which customers have an insurance policy with the type code "Deputy"? Give me the customer details. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT DISTINCT t2.customer_details FROM policies AS t1 JOIN customers AS t2 ON t1.customer_id = t2.customer_id WHERE t1.policy_type_code = "Deputy" OR t1.policy_type_code = "Uniform" | Find the names of customers who either have an deputy policy or uniformed policy. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT DISTINCT t2.customer_details FROM policies AS t1 JOIN customers AS t2 ON t1.customer_id = t2.customer_id WHERE t1.policy_type_code = "Deputy" OR t1.policy_type_code = "Uniform" | Which customers have an insurance policy with the type code "Deputy" or "Uniform"? Return the customer details. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT customer_details FROM customers UNION SELECT staff_details FROM staff | Find the names of all the customers and staff members. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT customer_details FROM customers UNION SELECT staff_details FROM staff | What are the names of the customers and staff members? | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT policy_type_code , count(*) FROM policies GROUP BY policy_type_code | Find the number of records of each policy type and its type code. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT policy_type_code , count(*) FROM policies GROUP BY policy_type_code | For each policy type, return its type code and its count in the record. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT t2.customer_details FROM policies AS t1 JOIN customers AS t2 ON t1.customer_id = t2.customer_id GROUP BY t2.customer_details ORDER BY count(*) DESC LIMIT 1 | Find the name of the customer that has been involved in the most policies. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT t2.customer_details FROM policies AS t1 JOIN customers AS t2 ON t1.customer_id = t2.customer_id GROUP BY t2.customer_details ORDER BY count(*) DESC LIMIT 1 | Which customer have the most policies? Give me the customer details. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT claim_status_description FROM claims_processing_stages WHERE claim_status_name = "Open" | What is the description of the claim status "Open"? | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT claim_status_description FROM claims_processing_stages WHERE claim_status_name = "Open" | Find the description of the claim status "Open". | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT count(DISTINCT claim_outcome_code) FROM claims_processing | How many distinct claim outcome codes are there? | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT count(DISTINCT claim_outcome_code) FROM claims_processing | Count the number of distinct claim outcome codes. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT t2.customer_details FROM policies AS t1 JOIN customers AS t2 ON t1.customer_id = t2.customer_id WHERE t1.start_date = (SELECT max(start_date) FROM policies) | Which customer is associated with the latest policy? | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
insurance_and_eClaims | SELECT t2.customer_details FROM policies AS t1 JOIN customers AS t2 ON t1.customer_id = t2.customer_id WHERE t1.start_date = (SELECT max(start_date) FROM policies) | Find the customer who started a policy most recently. | CREATE TABLE Customers (
Customer_ID INTEGER NOT NULL,
Customer_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Customer_ID)
);
CREATE TABLE Staff (
Staff_ID INTEGER NOT NULL,
Staff_Details VARCHAR(255) NOT NULL,
PRIMARY KEY (Staff_ID)
);
CREATE TABLE Policies (
Policy_ID INTEGER NOT NULL,
Customer_ID INTEGER NOT NULL,
Policy_Type_Code CHAR(15) NOT NULL,
Start_Date DATETIME,
End_Date DATETIME,
PRIMARY KEY (Policy_ID),
FOREIGN KEY (Customer_ID) REFERENCES Customers (Customer_ID)
);
CREATE TABLE Claim_Headers (
Claim_Header_ID INTEGER NOT NULL,
Claim_Status_Code CHAR(15) NOT NULL,
Claim_Type_Code CHAR(15) NOT NULL,
Policy_ID INTEGER NOT NULL,
Date_of_Claim DATETIME,
Date_of_Settlement DATETIME,
Amount_Claimed DECIMAL(20,4),
Amount_Piad DECIMAL(20,4),
PRIMARY KEY (Claim_Header_ID),
FOREIGN KEY (Policy_ID) REFERENCES Policies (Policy_ID)
);
CREATE TABLE Claims_Documents (
Claim_ID INTEGER NOT NULL,
Document_Type_Code CHAR(15) NOT NULL,
PRIMARY KEY (Claim_ID, Document_Type_Code),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
);
CREATE TABLE Claims_Processing_Stages (
Claim_Stage_ID INTEGER NOT NULL,
Next_Claim_Stage_ID INTEGER,
Claim_Status_Name VARCHAR(255) NOT NULL,
Claim_Status_Description VARCHAR(255) NOT NULL,
PRIMARY KEY (Claim_Stage_ID)
);
CREATE TABLE Claims_Processing (
Claim_Processing_ID INTEGER NOT NULL,
Claim_ID INTEGER NOT NULL,
Claim_Outcome_Code CHAR(15) NOT NULL,
Claim_Stage_ID INTEGER NOT NULL,
Staff_ID INTEGER,
PRIMARY KEY (Claim_Processing_ID),
FOREIGN KEY (Claim_ID) REFERENCES Claim_Headers (Claim_Header_ID),
FOREIGN KEY (Staff_ID) REFERENCES Staff (Staff_ID)
);
INSERT INTO `Customers` (`Customer_ID`, `Customer_Details`) VALUES (252, 'America Jaskolski');
INSERT INTO `Policies` (`Policy_ID`, `Customer_ID`, `Policy_Type_Code`, `Start_Date`, `End_Date`) VALUES (125, 808, 'Deputy', '2018-02-10 08:56:30', '2018-03-18 09:17:26');
INSERT INTO `Staff` (`Staff_ID`, `Staff_Details`) VALUES (406, 'Clifton');
INSERT INTO `Claim_Headers` (`Claim_Header_ID`, `Claim_Status_Code`, `Claim_Type_Code`, `Policy_ID`, `Date_of_Claim`, `Date_of_Settlement`, `Amount_Claimed`, `Amount_Piad`) VALUES (15, 'Settled', 'Handphone Subsidy', 518, '2016-05-31 06:07:11', '2018-02-23 03:46:38', '349.1500', '582.0300');
INSERT INTO `Claims_Processing_Stages` (`Claim_Stage_ID`, `Next_Claim_Stage_ID`, `Claim_Status_Name`, `Claim_Status_Description`) VALUES (1, 1, 'Open', 'Open a new claim');
INSERT INTO `Claims_Processing` (`Claim_Processing_ID`, `Claim_ID`, `Claim_Outcome_Code`, `Claim_Stage_ID`, `Staff_ID`) VALUES (118, 28, 'In progress', 1, 771); |
customers_and_invoices | SELECT count(*) FROM Accounts | Show the number of accounts. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT count(*) FROM Accounts | How many accounts are there? | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT count(DISTINCT customer_id) FROM Accounts | How many customers have opened an account? | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT count(DISTINCT customer_id) FROM Accounts | Count the number of customers who have an account. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT account_id , date_account_opened , account_name , other_account_details FROM Accounts | Show the id, the date of account opened, the account name, and other account detail for all accounts. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT account_id , date_account_opened , account_name , other_account_details FROM Accounts | What are the ids, date opened, name, and other details for all accounts? | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT T1.account_id , T1.date_account_opened , T1.account_name , T1.other_account_details FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE T2.customer_first_name = 'Meaghan' | Show the id, the account name, and other account details for all accounts by the customer with first name 'Meaghan'. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT T1.account_id , T1.date_account_opened , T1.account_name , T1.other_account_details FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE T2.customer_first_name = 'Meaghan' | What are the ids, names, dates of opening, and other details for accounts corresponding to the customer with the first name "Meaghan"? | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT T1.account_name , T1.other_account_details FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE T2.customer_first_name = "Meaghan" AND T2.customer_last_name = "Keeling" | Show the account name and other account detail for all accounts by the customer with first name Meaghan and last name Keeling. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT T1.account_name , T1.other_account_details FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE T2.customer_first_name = "Meaghan" AND T2.customer_last_name = "Keeling" | What are the names and other details for accounts corresponding to the customer named Meaghan Keeling? | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT T2.customer_first_name , T2.customer_last_name FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE T1.account_name = "900" | Show the first name and last name for the customer with account name 900. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT T2.customer_first_name , T2.customer_last_name FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE T1.account_name = "900" | What are the full names of customers with the account name 900? | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT count(*) FROM Customers WHERE customer_id NOT IN (SELECT customer_id FROM Accounts) | How many customers don't have an account? | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT count(*) FROM Customers WHERE customer_id NOT IN (SELECT customer_id FROM Accounts) | Count the number of customers who do not have an account. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT DISTINCT T1.customer_first_name , T1.customer_last_name , T1.phone_number FROM Customers AS T1 JOIN Accounts AS T2 ON T1.customer_id = T2.customer_id | Show the unique first names, last names, and phone numbers for all customers with any account. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT DISTINCT T1.customer_first_name , T1.customer_last_name , T1.phone_number FROM Customers AS T1 JOIN Accounts AS T2 ON T1.customer_id = T2.customer_id | What are the distinct first names, last names, and phone numbers for customers with accounts? | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT customer_id FROM Customers EXCEPT SELECT customer_id FROM Accounts | Show customer ids who don't have an account. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT customer_id FROM Customers EXCEPT SELECT customer_id FROM Accounts | What are the customer ids for customers who do not have an account? | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT count(*) , customer_id FROM Accounts GROUP BY customer_id | How many accounts does each customer have? List the number and customer id. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT count(*) , customer_id FROM Accounts GROUP BY customer_id | Count the number of accounts corresponding to each customer id. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT T1.customer_id , T2.customer_first_name , T2.customer_last_name FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1 | What is the customer id, first and last name with most number of accounts. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT T1.customer_id , T2.customer_first_name , T2.customer_last_name FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1 | Return the id and full name of the customer with the most accounts. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT T1.customer_id , T2.customer_first_name , T2.customer_last_name , count(*) FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id | Show id, first name and last name for all customers and the number of accounts. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT T1.customer_id , T2.customer_first_name , T2.customer_last_name , count(*) FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id | What are the the full names and ids for all customers, and how many accounts does each have? | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT T2.customer_first_name , T1.customer_id FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id HAVING count(*) >= 2 | Show first name and id for all customers with at least 2 accounts. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT T2.customer_first_name , T1.customer_id FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id HAVING count(*) >= 2 | What are the first names and ids for customers who have two or more accounts? | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT count(*) FROM Customers | Show the number of customers. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT count(*) FROM Customers | Count the number of customers. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT gender , count(*) FROM Customers GROUP BY gender | Show the number of customers for each gender. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT gender , count(*) FROM Customers GROUP BY gender | How many customers are there of each gender? | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT count(*) FROM Financial_transactions | How many transactions do we have? | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT count(*) FROM Financial_transactions | Count the number of transactions. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT count(*) , account_id FROM Financial_transactions | How many transaction does each account have? Show the number and account id. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |
customers_and_invoices | SELECT count(*) , account_id FROM Financial_transactions | Count the number of financial transactions that correspond to each account id. | CREATE TABLE `Customers` (
`customer_id` INTEGER PRIMARY KEY,
`customer_first_name` VARCHAR(50),
`customer_middle_initial` VARCHAR(1),
`customer_last_name` VARCHAR(50),
`gender` VARCHAR(1),
`email_address` VARCHAR(255),
`login_name` VARCHAR(80),
`login_password` VARCHAR(20),
`phone_number` VARCHAR(255),
`town_city` VARCHAR(50),
`state_county_province` VARCHAR(50),
`country` VARCHAR(50)
);
CREATE TABLE `Orders` (
`order_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_order_placed` DATETIME NOT NULL,
`order_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Invoices` (
`invoice_number` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`invoice_date` DATETIME,
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Accounts` (
`account_id` INTEGER PRIMARY KEY,
`customer_id` INTEGER NOT NULL,
`date_account_opened` DATETIME,
`account_name` VARCHAR(50),
`other_account_details` VARCHAR(255),
FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` )
);
CREATE TABLE `Product_Categories` (
`production_type_code` VARCHAR(15) PRIMARY KEY,
`product_type_description` VARCHAR(80),
`vat_rating` DECIMAL(19,4)
);
CREATE TABLE `Products` (
`product_id` INTEGER PRIMARY KEY,
`parent_product_id` INTEGER,
`production_type_code` VARCHAR(15) NOT NULL,
`unit_price` DECIMAL(19,4),
`product_name` VARCHAR(80),
`product_color` VARCHAR(20),
`product_size` VARCHAR(20),
FOREIGN KEY (`production_type_code` ) REFERENCES `Product_Categories`(`production_type_code` )
);
CREATE TABLE `Financial_Transactions` (
`transaction_id` INTEGER NOT NULL ,
`account_id` INTEGER NOT NULL,
`invoice_number` INTEGER,
`transaction_type` VARCHAR(15) NOT NULL,
`transaction_date` DATETIME,
`transaction_amount` DECIMAL(19,4),
`transaction_comment` VARCHAR(255),
`other_transaction_details` VARCHAR(255),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`account_id` ) REFERENCES `Accounts`(`account_id` )
);
CREATE TABLE `Order_Items` (
`order_item_id` INTEGER PRIMARY KEY,
`order_id` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_quantity` VARCHAR(50),
`other_order_item_details` VARCHAR(255),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ),
FOREIGN KEY (`order_id` ) REFERENCES `Orders`(`order_id` )
);
CREATE TABLE `Invoice_Line_Items` (
`order_item_id` INTEGER NOT NULL,
`invoice_number` INTEGER NOT NULL,
`product_id` INTEGER NOT NULL,
`product_title` VARCHAR(80),
`product_quantity` VARCHAR(50),
`product_price` DECIMAL(19,4),
`derived_product_cost` DECIMAL(19,4),
`derived_vat_payable` DECIMAL(19,4),
`derived_total_cost` DECIMAL(19,4),
FOREIGN KEY (`order_item_id` ) REFERENCES `Order_Items`(`order_item_id` ),
FOREIGN KEY (`invoice_number` ) REFERENCES `Invoices`(`invoice_number` ),
FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` )
);
INSERT INTO Customers (`customer_id`, `customer_first_name`, `customer_middle_initial`, `customer_last_name`, `gender`, `email_address`, `login_name`, `login_password`, `phone_number`, `town_city`, `state_county_province`, `country`) VALUES (1, 'Dee', 'A', 'Larkin', '1', 'thora.torphy@example.org', 'xhartmann', '77789d292604ea04406f', '241.796.1219x37862', 'North Nellie', 'WestVirginia', 'USA');
INSERT INTO Orders (`order_id`, `customer_id`, `date_order_placed`, `order_details`) VALUES (1, 12, '2012-06-27 20:49:56', NULL);
INSERT INTO Invoices (`invoice_number`, `order_id`, `invoice_date`) VALUES (1, 9, '2018-03-01 16:40:48');
INSERT INTO Accounts (`account_id`, `customer_id`, `date_account_opened`, `account_name`, `other_account_details`) VALUES (1, 8, '2016-07-30 22:22:24', '900', 'Regular');
INSERT INTO Product_Categories (`production_type_code`, `product_type_description`, `vat_rating`) VALUES ('Food', 'Food', '15.8400');
INSERT INTO Products (`product_id`, `parent_product_id`, `production_type_code`, `unit_price`, `product_name`, `product_color`, `product_size`) VALUES (1, 4, 'Food', '617.9500', 'Coffee Bean', 'Red', 'Medium');
INSERT INTO Financial_Transactions (`transaction_id`, `account_id`, `invoice_number`, `transaction_type`, `transaction_date`, `transaction_amount`) VALUES (1, 13, 12, 'Payment', '2018-03-15 21:13:57', '613.9600');
INSERT INTO Order_Items (`order_item_id`, `order_id`, `product_id`, `product_quantity`, `other_order_item_details`) VALUES (1, 4, 4, '6', NULL);
INSERT INTO Invoice_Line_Items (`order_item_id`, `invoice_number`, `product_id`, `product_title`, `product_quantity`, `product_price`, `derived_product_cost`, `derived_vat_payable`, `derived_total_cost`) VALUES (14, 9, 5, 'prod_name', '4', '742.3700', '191.1100', NULL, '69.8200'); |