spider_version
int64
1
2
db_id
stringclasses
204 values
schema
stringclasses
187 values
question
stringlengths
3
328
query
stringlengths
20
3.81k
1
dorm_1
What amenities does Smith Hall have in alphabetical order?
SELECT T3.amenity_name FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid WHERE T1.dorm_name = 'Smith Hall' ORDER BY T3.amenity_name
1
dorm_1
Find the name of amenity that is most common in all dorms.
SELECT T1.amenity_name FROM dorm_amenity AS T1 JOIN has_amenity AS T2 ON T1.amenid = T2.amenid GROUP BY T2.amenid ORDER BY count(*) DESC LIMIT 1
1
dorm_1
What is the most common amenity in the dorms?
SELECT T1.amenity_name FROM dorm_amenity AS T1 JOIN has_amenity AS T2 ON T1.amenid = T2.amenid GROUP BY T2.amenid ORDER BY count(*) DESC LIMIT 1
1
dorm_1
Find the first name of students who are living in the dorm that has most number of amenities.
SELECT T1.fname FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid WHERE T2.dormid IN (SELECT T2.dormid FROM dorm AS T3 JOIN has_amenity AS T4 ON T3.dormid = T4.dormid JOIN dorm_amenity AS T5 ON T4.amenid = T5.amenid GROUP BY T3.dormid ORDER BY count(*) DESC LIMIT 1)
1
dorm_1
What are the first names of all students who live in the dorm with the most amenities?
SELECT T1.fname FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid WHERE T2.dormid IN (SELECT T2.dormid FROM dorm AS T3 JOIN has_amenity AS T4 ON T3.dormid = T4.dormid JOIN dorm_amenity AS T5 ON T4.amenid = T5.amenid GROUP BY T3.dormid ORDER BY count(*) DESC LIMIT 1)
1
dorm_1
Find the name and capacity of the dorm with least number of amenities.
SELECT T1.dorm_name , T1.student_capacity FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid GROUP BY T2.dormid ORDER BY count(*) LIMIT 1
1
dorm_1
What is the name and capacity of the dorm with the fewest amount of amenities?
SELECT T1.dorm_name , T1.student_capacity FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid GROUP BY T2.dormid ORDER BY count(*) LIMIT 1
1
dorm_1
Find the name of dorms that do not have amenity TV Lounge.
SELECT dorm_name FROM dorm EXCEPT SELECT T1.dorm_name FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid WHERE T3.amenity_name = 'TV Lounge'
1
dorm_1
What are the names of the dorm that does not have a TV Lounge?
SELECT dorm_name FROM dorm EXCEPT SELECT T1.dorm_name FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid WHERE T3.amenity_name = 'TV Lounge'
1
dorm_1
Find the first and last name of students who are living in the dorms that have amenity TV Lounge.
SELECT T1.fname , T1.lname FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid WHERE T2.dormid IN (SELECT T3.dormid FROM has_amenity AS T3 JOIN dorm_amenity AS T4 ON T3.amenid = T4.amenid WHERE T4.amenity_name = 'TV Lounge')
1
dorm_1
What are the first and last names of all students who are living in a dorm with a TV Lounge?
SELECT T1.fname , T1.lname FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid WHERE T2.dormid IN (SELECT T3.dormid FROM has_amenity AS T3 JOIN dorm_amenity AS T4 ON T3.amenid = T4.amenid WHERE T4.amenity_name = 'TV Lounge')
1
dorm_1
Find the first name and age of students who are living in the dorms that do not have amenity TV Lounge.
SELECT T1.fname , T1.age FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid WHERE T2.dormid NOT IN (SELECT T3.dormid FROM has_amenity AS T3 JOIN dorm_amenity AS T4 ON T3.amenid = T4.amenid WHERE T4.amenity_name = 'TV Lounge')
1
dorm_1
What is the first name and age of every student who lives in a dorm with a TV Lounge?
SELECT T1.fname , T1.age FROM student AS T1 JOIN lives_in AS T2 ON T1.stuid = T2.stuid WHERE T2.dormid NOT IN (SELECT T3.dormid FROM has_amenity AS T3 JOIN dorm_amenity AS T4 ON T3.amenid = T4.amenid WHERE T4.amenity_name = 'TV Lounge')
1
dorm_1
Find the name of amenities of the dorm where the student with last name Smith is living in.
SELECT T3.amenity_name FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid JOIN lives_in AS T4 ON T4.dormid = T1.dormid JOIN student AS T5 ON T5.stuid = T4.stuid WHERE T5.lname = 'Smith'
1
dorm_1
What are the amenities in the dorm that a student who has the last name of Smith lives in?
SELECT T3.amenity_name FROM dorm AS T1 JOIN has_amenity AS T2 ON T1.dormid = T2.dormid JOIN dorm_amenity AS T3 ON T2.amenid = T3.amenid JOIN lives_in AS T4 ON T4.dormid = T1.dormid JOIN student AS T5 ON T5.stuid = T4.stuid WHERE T5.lname = 'Smith'
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
How many customers are there?
SELECT count(*) FROM customers
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Count the number of customers.
SELECT count(*) FROM customers
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Find the emails and phone numbers of all the customers, ordered by email address and phone number.
SELECT email_address , phone_number FROM customers ORDER BY email_address , phone_number
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
What are the emails and phone numbers of all customers, sorted by email address and phone number?
SELECT email_address , phone_number FROM customers ORDER BY email_address , phone_number
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Which city has the least number of customers whose type code is "Good Credit Rating"?
SELECT town_city FROM customers WHERE customer_type_code = "Good Credit Rating" GROUP BY town_city ORDER BY count(*) LIMIT 1
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Return the city with the customer type code "Good Credit Rating" that had the fewest customers.
SELECT town_city FROM customers WHERE customer_type_code = "Good Credit Rating" GROUP BY town_city ORDER BY count(*) LIMIT 1
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
List the name of all products along with the number of complaints that they have received.
SELECT t1.product_name , count(*) FROM products AS t1 JOIN complaints AS t2 ON t1.product_id = t2.product_id GROUP BY t1.product_name
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
What are all the different product names, and how many complains has each received?
SELECT t1.product_name , count(*) FROM products AS t1 JOIN complaints AS t2 ON t1.product_id = t2.product_id GROUP BY t1.product_name
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Find the emails of customers who has filed a complaints of the product with the most complaints.
SELECT t1.email_address FROM customers AS t1 JOIN complaints AS t2 ON t1.customer_id = t2.customer_id GROUP BY t1.customer_id ORDER BY count(*) LIMIT 1
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
What are the emails of customers who have filed complaints on the product which has had the greatest number of complaints?
SELECT t1.email_address FROM customers AS t1 JOIN complaints AS t2 ON t1.customer_id = t2.customer_id GROUP BY t1.customer_id ORDER BY count(*) LIMIT 1
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Which products has been complained by the customer who has filed least amount of complaints?
SELECT DISTINCT t1.product_name FROM products AS t1 JOIN complaints AS t2 ON t1.product_id = t2.product_id JOIN customers AS t3 GROUP BY t3.customer_id ORDER BY count(*) LIMIT 1
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Return the names of products that have had complaints filed by the customer who has filed the fewest complaints.
SELECT DISTINCT t1.product_name FROM products AS t1 JOIN complaints AS t2 ON t1.product_id = t2.product_id JOIN customers AS t3 GROUP BY t3.customer_id ORDER BY count(*) LIMIT 1
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
What is the phone number of the customer who has filed the most recent complaint?
SELECT t1.phone_number FROM customers AS t1 JOIN complaints AS t2 ON t1.customer_id = t2.customer_id ORDER BY t2.date_complaint_raised DESC LIMIT 1
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Return the phone number of the customer who filed the complaint that was raised most recently.
SELECT t1.phone_number FROM customers AS t1 JOIN complaints AS t2 ON t1.customer_id = t2.customer_id ORDER BY t2.date_complaint_raised DESC LIMIT 1
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Find the email and phone number of the customers who have never filed a complaint before.
SELECT email_address , phone_number FROM customers WHERE customer_id NOT IN (SELECT customer_id FROM complaints)
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
What are the emails and phone numbers of custoemrs who have never filed a complaint?
SELECT email_address , phone_number FROM customers WHERE customer_id NOT IN (SELECT customer_id FROM complaints)
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Find the phone number of all the customers and staff.
SELECT phone_number FROM customers UNION SELECT phone_number FROM staff
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
What are the phone numbers of all customers and all staff members?
SELECT phone_number FROM customers UNION SELECT phone_number FROM staff
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
What is the description of the product named "Chocolate"?
SELECT product_description FROM products WHERE product_name = "Chocolate"
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Return the description of the product called "Chocolate".
SELECT product_description FROM products WHERE product_name = "Chocolate"
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Find the name and category of the most expensive product.
SELECT product_name , product_category_code FROM products ORDER BY product_price DESC LIMIT 1
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
What is the name and category code of the product with the highest price?
SELECT product_name , product_category_code FROM products ORDER BY product_price DESC LIMIT 1
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Find the prices of products which has never received a single complaint.
SELECT product_price FROM products WHERE product_id NOT IN (SELECT product_id FROM complaints)
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
What are the prices of products that have never gotten a complaint?
SELECT product_price FROM products WHERE product_id NOT IN (SELECT product_id FROM complaints)
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
What is the average price of the products for each category?
SELECT avg(product_price) , product_category_code FROM products GROUP BY product_category_code
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Return the average price of products that have each category code.
SELECT avg(product_price) , product_category_code FROM products GROUP BY product_category_code
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Find the last name of the staff member who processed the complaint of the cheapest product.
SELECT t1.last_name FROM staff AS t1 JOIN complaints AS t2 ON t1.staff_id = t2.staff_id JOIN products AS t3 ON t2.product_id = t3.product_id ORDER BY t3.product_price LIMIT 1
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
What is the last name of the staff member in charge of the complaint on the product with the lowest price?
SELECT t1.last_name FROM staff AS t1 JOIN complaints AS t2 ON t1.staff_id = t2.staff_id JOIN products AS t3 ON t2.product_id = t3.product_id ORDER BY t3.product_price LIMIT 1
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Which complaint status has more than 3 records on file?
SELECT complaint_status_code FROM complaints GROUP BY complaint_status_code HAVING count(*) > 3
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Return complaint status codes have more than 3 corresponding complaints?
SELECT complaint_status_code FROM complaints GROUP BY complaint_status_code HAVING count(*) > 3
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Find the last name of the staff whose email address contains "wrau".
SELECT last_name FROM staff WHERE email_address LIKE "%wrau%"
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
What are the last names of staff with email addressed containing the substring "wrau"?
SELECT last_name FROM staff WHERE email_address LIKE "%wrau%"
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
How many customers are there in the customer type with the most customers?
SELECT count(*) FROM customers GROUP BY customer_type_code ORDER BY count(*) DESC LIMIT 1
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Count the number of customers that have the customer type that is most common.
SELECT count(*) FROM customers GROUP BY customer_type_code ORDER BY count(*) DESC LIMIT 1
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
What is the last name of the staff who has handled the first ever complaint?
SELECT t1.last_name FROM staff AS t1 JOIN complaints AS t2 ON t1.staff_id = t2.staff_id ORDER BY t2.date_complaint_raised LIMIT 1
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Return the last name of the staff member who handled the complaint with the earliest date raised.
SELECT t1.last_name FROM staff AS t1 JOIN complaints AS t2 ON t1.staff_id = t2.staff_id ORDER BY t2.date_complaint_raised LIMIT 1
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
How many distinct complaint type codes are there in the database?
SELECT count(DISTINCT complaint_type_code) FROM complaints
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Count the number of different complaint type codes.
SELECT count(DISTINCT complaint_type_code) FROM complaints
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Find the address line 1 and 2 of the customer with email "vbogisich@example.org".
SELECT address_line_1 , address_line_2 FROM customers WHERE email_address = "vbogisich@example.org"
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
What are lines 1 and 2 of the addressed of the customer with the email "vbogisich@example.org"?
SELECT address_line_1 , address_line_2 FROM customers WHERE email_address = "vbogisich@example.org"
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Find the number of complaints with Product Failure type for each complaint status.
SELECT complaint_status_code , count(*) FROM complaints WHERE complaint_type_code = "Product Failure" GROUP BY complaint_status_code
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Of complaints with the type code "Product Failure", how many had each different status code?
SELECT complaint_status_code , count(*) FROM complaints WHERE complaint_type_code = "Product Failure" GROUP BY complaint_status_code
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
What is first names of the top 5 staff who have handled the greatest number of complaints?
SELECT t1.first_name FROM staff AS t1 JOIN complaints AS t2 ON t1.staff_id = t2.staff_id GROUP BY t2.staff_id ORDER BY count(*) LIMIT 5
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Return the first names of the 5 staff members who have handled the most complaints.
SELECT t1.first_name FROM staff AS t1 JOIN complaints AS t2 ON t1.staff_id = t2.staff_id GROUP BY t2.staff_id ORDER BY count(*) LIMIT 5
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Which state has the most customers?
SELECT state FROM customers GROUP BY state ORDER BY count(*) LIMIT 1
1
customer_complaints
CREATE TABLE `Staff` ( `staff_id` INTEGER PRIMARY KEY, `gender` VARCHAR(1), `first_name` VARCHAR(80), `last_name` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `customer_type_code` VARCHAR(20) NOT NULL, `address_line_1` VARCHAR(80), `address_line_2` VARCHAR(80), `town_city` VARCHAR(80), `state` VARCHAR(80), `email_address` VARCHAR(255), `phone_number` VARCHAR(80) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `parent_product_id` INTEGER, `product_category_code` VARCHAR(20) NOT NULL, `date_product_first_available` DATETIME, `date_product_discontinued` DATETIME, `product_name` VARCHAR(80), `product_description` VARCHAR(255), `product_price` DECIMAL(19,4) ); CREATE TABLE `Complaints` ( `complaint_id` INTEGER NOT NULL , `product_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `complaint_outcome_code` VARCHAR(20) NOT NULL, `complaint_status_code` VARCHAR(20) NOT NULL, `complaint_type_code` VARCHAR(20) NOT NULL, `date_complaint_raised` DATETIME, `date_complaint_closed` DATETIME, `staff_id` INTEGER NOT NULL , FOREIGN KEY (`staff_id` ) REFERENCES `Staff`(`staff_id` ), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) )
Give the state that has the most customers.
SELECT state FROM customers GROUP BY state ORDER BY count(*) LIMIT 1
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
How many submissions are there?
SELECT count(*) FROM submission
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
Count the number of submissions.
SELECT count(*) FROM submission
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
List the authors of submissions in ascending order of scores.
SELECT Author FROM submission ORDER BY Scores ASC
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
Find the author for each submission and list them in ascending order of submission score.
SELECT Author FROM submission ORDER BY Scores ASC
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
What are the authors of submissions and their colleges?
SELECT Author , College FROM submission
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
For each submission, show the author and their affiliated college.
SELECT Author , College FROM submission
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
Show the names of authors from college "Florida" or "Temple"
SELECT Author FROM submission WHERE College = "Florida" OR College = "Temple"
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
Which authors with submissions are from college "Florida" or "Temple"?
SELECT Author FROM submission WHERE College = "Florida" OR College = "Temple"
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
What is the average score of submissions?
SELECT avg(Scores) FROM submission
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
Compute the average score of submissions.
SELECT avg(Scores) FROM submission
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
What is the author of the submission with the highest score?
SELECT Author FROM submission ORDER BY Scores DESC LIMIT 1
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
Find the author who achieved the highest score in a submission.
SELECT Author FROM submission ORDER BY Scores DESC LIMIT 1
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
Show different colleges along with the number of authors of submission from each college.
SELECT College , COUNT(*) FROM submission GROUP BY College
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
For each college, return the college name and the count of authors with submissions from that college.
SELECT College , COUNT(*) FROM submission GROUP BY College
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
Show the most common college of authors of submissions.
SELECT College FROM submission GROUP BY College ORDER BY COUNT(*) DESC LIMIT 1
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
Which college has the most authors with submissions?
SELECT College FROM submission GROUP BY College ORDER BY COUNT(*) DESC LIMIT 1
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
Show the colleges that have both authors with submission score larger than 90 and authors with submission score smaller than 80.
SELECT College FROM submission WHERE Scores > 90 INTERSECT SELECT College FROM submission WHERE Scores < 80
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
Which colleges have both authors with submission score above 90 and authors with submission score below 80?
SELECT College FROM submission WHERE Scores > 90 INTERSECT SELECT College FROM submission WHERE Scores < 80
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
Show the authors of submissions and the acceptance results of their submissions.
SELECT T2.Author , T1.Result FROM acceptance AS T1 JOIN submission AS T2 ON T1.Submission_ID = T2.Submission_ID
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
For each submission, find its author and acceptance result.
SELECT T2.Author , T1.Result FROM acceptance AS T1 JOIN submission AS T2 ON T1.Submission_ID = T2.Submission_ID
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
Show the result of the submission with the highest score.
SELECT T1.Result FROM acceptance AS T1 JOIN submission AS T2 ON T1.Submission_ID = T2.Submission_ID ORDER BY T2.Scores DESC LIMIT 1
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
Which submission received the highest score in acceptance result. Show me the result.
SELECT T1.Result FROM acceptance AS T1 JOIN submission AS T2 ON T1.Submission_ID = T2.Submission_ID ORDER BY T2.Scores DESC LIMIT 1
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
Show each author and the number of workshops they submitted to.
SELECT T2.Author , COUNT(DISTINCT T1.workshop_id) FROM acceptance AS T1 JOIN submission AS T2 ON T1.Submission_ID = T2.Submission_ID GROUP BY T2.Author
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
How many workshops did each author submit to? Return the author name and the number of workshops.
SELECT T2.Author , COUNT(DISTINCT T1.workshop_id) FROM acceptance AS T1 JOIN submission AS T2 ON T1.Submission_ID = T2.Submission_ID GROUP BY T2.Author
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
Show the authors who have submissions to more than one workshop.
SELECT T2.Author FROM acceptance AS T1 JOIN submission AS T2 ON T1.Submission_ID = T2.Submission_ID GROUP BY T2.Author HAVING COUNT(DISTINCT T1.workshop_id) > 1
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
Which authors have submitted to more than one workshop?
SELECT T2.Author FROM acceptance AS T1 JOIN submission AS T2 ON T1.Submission_ID = T2.Submission_ID GROUP BY T2.Author HAVING COUNT(DISTINCT T1.workshop_id) > 1
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
Show the date and venue of each workshop in ascending alphabetical order of the venue.
SELECT Date , Venue FROM workshop ORDER BY Venue
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
Sort the each workshop in alphabetical order of the venue. Return the date and venue of each workshop.
SELECT Date , Venue FROM workshop ORDER BY Venue
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
List the authors who do not have submission to any workshop.
SELECT Author FROM submission WHERE Submission_ID NOT IN (SELECT Submission_ID FROM acceptance)
1
workshop_paper
CREATE TABLE "workshop" ( "Workshop_ID" int, "Date" text, "Venue" text, "Name" text, PRIMARY KEY ("Workshop_ID") ); CREATE TABLE "submission" ( "Submission_ID" int, "Scores" real, "Author" text, "College" text, PRIMARY KEY ("Submission_ID") ); CREATE TABLE "Acceptance" ( "Submission_ID" int, "Workshop_ID" int, "Result" text, PRIMARY KEY ("Submission_ID","Workshop_ID"), FOREIGN KEY ("Submission_ID") REFERENCES `submission`("Submission_ID"), FOREIGN KEY ("Workshop_ID") REFERENCES `workshop`("Workshop_ID") )
Which authors did not submit to any workshop?
SELECT Author FROM submission WHERE Submission_ID NOT IN (SELECT Submission_ID FROM acceptance)
1
tracking_share_transactions
CREATE TABLE `Investors` ( `investor_id` INTEGER PRIMARY KEY, `Investor_details` VARCHAR(255) ); CREATE TABLE `Lots` ( `lot_id` INTEGER PRIMARY KEY, `investor_id` INTEGER NOT NULL, `lot_details` VARCHAR(255), FOREIGN KEY (`investor_id` ) REFERENCES `Investors`(`investor_id` ) ); CREATE TABLE `Ref_Transaction_Types` ( `transaction_type_code` VARCHAR(10) PRIMARY KEY, `transaction_type_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Transactions` ( `transaction_id` INTEGER PRIMARY KEY, `investor_id` INTEGER NOT NULL, `transaction_type_code` VARCHAR(10) NOT NULL, `date_of_transaction` DATETIME, `amount_of_transaction` DECIMAL(19,4), `share_count` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`investor_id` ) REFERENCES `Investors`(`investor_id` ),FOREIGN KEY (`transaction_type_code` ) REFERENCES `Ref_Transaction_Types`(`transaction_type_code` ) ); CREATE TABLE `Sales` ( `sales_transaction_id` INTEGER PRIMARY KEY, `sales_details` VARCHAR(255), FOREIGN KEY (`sales_transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) ); CREATE TABLE `Purchases` ( `purchase_transaction_id` INTEGER NOT NULL, `purchase_details` VARCHAR(255) NOT NULL, FOREIGN KEY (`purchase_transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) ); CREATE TABLE `Transactions_Lots` ( `transaction_id` INTEGER NOT NULL, `lot_id` INTEGER NOT NULL, FOREIGN KEY (`lot_id` ) REFERENCES `Lots`(`lot_id` ), FOREIGN KEY (`transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) )
Find the number of investors in total.
SELECT count(*) FROM INVESTORS
1
tracking_share_transactions
CREATE TABLE `Investors` ( `investor_id` INTEGER PRIMARY KEY, `Investor_details` VARCHAR(255) ); CREATE TABLE `Lots` ( `lot_id` INTEGER PRIMARY KEY, `investor_id` INTEGER NOT NULL, `lot_details` VARCHAR(255), FOREIGN KEY (`investor_id` ) REFERENCES `Investors`(`investor_id` ) ); CREATE TABLE `Ref_Transaction_Types` ( `transaction_type_code` VARCHAR(10) PRIMARY KEY, `transaction_type_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Transactions` ( `transaction_id` INTEGER PRIMARY KEY, `investor_id` INTEGER NOT NULL, `transaction_type_code` VARCHAR(10) NOT NULL, `date_of_transaction` DATETIME, `amount_of_transaction` DECIMAL(19,4), `share_count` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`investor_id` ) REFERENCES `Investors`(`investor_id` ),FOREIGN KEY (`transaction_type_code` ) REFERENCES `Ref_Transaction_Types`(`transaction_type_code` ) ); CREATE TABLE `Sales` ( `sales_transaction_id` INTEGER PRIMARY KEY, `sales_details` VARCHAR(255), FOREIGN KEY (`sales_transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) ); CREATE TABLE `Purchases` ( `purchase_transaction_id` INTEGER NOT NULL, `purchase_details` VARCHAR(255) NOT NULL, FOREIGN KEY (`purchase_transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) ); CREATE TABLE `Transactions_Lots` ( `transaction_id` INTEGER NOT NULL, `lot_id` INTEGER NOT NULL, FOREIGN KEY (`lot_id` ) REFERENCES `Lots`(`lot_id` ), FOREIGN KEY (`transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) )
Show all investor details.
SELECT Investor_details FROM INVESTORS
1
tracking_share_transactions
CREATE TABLE `Investors` ( `investor_id` INTEGER PRIMARY KEY, `Investor_details` VARCHAR(255) ); CREATE TABLE `Lots` ( `lot_id` INTEGER PRIMARY KEY, `investor_id` INTEGER NOT NULL, `lot_details` VARCHAR(255), FOREIGN KEY (`investor_id` ) REFERENCES `Investors`(`investor_id` ) ); CREATE TABLE `Ref_Transaction_Types` ( `transaction_type_code` VARCHAR(10) PRIMARY KEY, `transaction_type_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Transactions` ( `transaction_id` INTEGER PRIMARY KEY, `investor_id` INTEGER NOT NULL, `transaction_type_code` VARCHAR(10) NOT NULL, `date_of_transaction` DATETIME, `amount_of_transaction` DECIMAL(19,4), `share_count` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`investor_id` ) REFERENCES `Investors`(`investor_id` ),FOREIGN KEY (`transaction_type_code` ) REFERENCES `Ref_Transaction_Types`(`transaction_type_code` ) ); CREATE TABLE `Sales` ( `sales_transaction_id` INTEGER PRIMARY KEY, `sales_details` VARCHAR(255), FOREIGN KEY (`sales_transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) ); CREATE TABLE `Purchases` ( `purchase_transaction_id` INTEGER NOT NULL, `purchase_details` VARCHAR(255) NOT NULL, FOREIGN KEY (`purchase_transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) ); CREATE TABLE `Transactions_Lots` ( `transaction_id` INTEGER NOT NULL, `lot_id` INTEGER NOT NULL, FOREIGN KEY (`lot_id` ) REFERENCES `Lots`(`lot_id` ), FOREIGN KEY (`transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) )
Show all distinct lot details.
SELECT DISTINCT lot_details FROM LOTS
1
tracking_share_transactions
CREATE TABLE `Investors` ( `investor_id` INTEGER PRIMARY KEY, `Investor_details` VARCHAR(255) ); CREATE TABLE `Lots` ( `lot_id` INTEGER PRIMARY KEY, `investor_id` INTEGER NOT NULL, `lot_details` VARCHAR(255), FOREIGN KEY (`investor_id` ) REFERENCES `Investors`(`investor_id` ) ); CREATE TABLE `Ref_Transaction_Types` ( `transaction_type_code` VARCHAR(10) PRIMARY KEY, `transaction_type_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Transactions` ( `transaction_id` INTEGER PRIMARY KEY, `investor_id` INTEGER NOT NULL, `transaction_type_code` VARCHAR(10) NOT NULL, `date_of_transaction` DATETIME, `amount_of_transaction` DECIMAL(19,4), `share_count` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`investor_id` ) REFERENCES `Investors`(`investor_id` ),FOREIGN KEY (`transaction_type_code` ) REFERENCES `Ref_Transaction_Types`(`transaction_type_code` ) ); CREATE TABLE `Sales` ( `sales_transaction_id` INTEGER PRIMARY KEY, `sales_details` VARCHAR(255), FOREIGN KEY (`sales_transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) ); CREATE TABLE `Purchases` ( `purchase_transaction_id` INTEGER NOT NULL, `purchase_details` VARCHAR(255) NOT NULL, FOREIGN KEY (`purchase_transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) ); CREATE TABLE `Transactions_Lots` ( `transaction_id` INTEGER NOT NULL, `lot_id` INTEGER NOT NULL, FOREIGN KEY (`lot_id` ) REFERENCES `Lots`(`lot_id` ), FOREIGN KEY (`transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) )
Show the maximum amount of transaction.
SELECT max(amount_of_transaction) FROM TRANSACTIONS
1
tracking_share_transactions
CREATE TABLE `Investors` ( `investor_id` INTEGER PRIMARY KEY, `Investor_details` VARCHAR(255) ); CREATE TABLE `Lots` ( `lot_id` INTEGER PRIMARY KEY, `investor_id` INTEGER NOT NULL, `lot_details` VARCHAR(255), FOREIGN KEY (`investor_id` ) REFERENCES `Investors`(`investor_id` ) ); CREATE TABLE `Ref_Transaction_Types` ( `transaction_type_code` VARCHAR(10) PRIMARY KEY, `transaction_type_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Transactions` ( `transaction_id` INTEGER PRIMARY KEY, `investor_id` INTEGER NOT NULL, `transaction_type_code` VARCHAR(10) NOT NULL, `date_of_transaction` DATETIME, `amount_of_transaction` DECIMAL(19,4), `share_count` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`investor_id` ) REFERENCES `Investors`(`investor_id` ),FOREIGN KEY (`transaction_type_code` ) REFERENCES `Ref_Transaction_Types`(`transaction_type_code` ) ); CREATE TABLE `Sales` ( `sales_transaction_id` INTEGER PRIMARY KEY, `sales_details` VARCHAR(255), FOREIGN KEY (`sales_transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) ); CREATE TABLE `Purchases` ( `purchase_transaction_id` INTEGER NOT NULL, `purchase_details` VARCHAR(255) NOT NULL, FOREIGN KEY (`purchase_transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) ); CREATE TABLE `Transactions_Lots` ( `transaction_id` INTEGER NOT NULL, `lot_id` INTEGER NOT NULL, FOREIGN KEY (`lot_id` ) REFERENCES `Lots`(`lot_id` ), FOREIGN KEY (`transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) )
Show all date and share count of transactions.
SELECT date_of_transaction , share_count FROM TRANSACTIONS
1
tracking_share_transactions
CREATE TABLE `Investors` ( `investor_id` INTEGER PRIMARY KEY, `Investor_details` VARCHAR(255) ); CREATE TABLE `Lots` ( `lot_id` INTEGER PRIMARY KEY, `investor_id` INTEGER NOT NULL, `lot_details` VARCHAR(255), FOREIGN KEY (`investor_id` ) REFERENCES `Investors`(`investor_id` ) ); CREATE TABLE `Ref_Transaction_Types` ( `transaction_type_code` VARCHAR(10) PRIMARY KEY, `transaction_type_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Transactions` ( `transaction_id` INTEGER PRIMARY KEY, `investor_id` INTEGER NOT NULL, `transaction_type_code` VARCHAR(10) NOT NULL, `date_of_transaction` DATETIME, `amount_of_transaction` DECIMAL(19,4), `share_count` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`investor_id` ) REFERENCES `Investors`(`investor_id` ),FOREIGN KEY (`transaction_type_code` ) REFERENCES `Ref_Transaction_Types`(`transaction_type_code` ) ); CREATE TABLE `Sales` ( `sales_transaction_id` INTEGER PRIMARY KEY, `sales_details` VARCHAR(255), FOREIGN KEY (`sales_transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) ); CREATE TABLE `Purchases` ( `purchase_transaction_id` INTEGER NOT NULL, `purchase_details` VARCHAR(255) NOT NULL, FOREIGN KEY (`purchase_transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) ); CREATE TABLE `Transactions_Lots` ( `transaction_id` INTEGER NOT NULL, `lot_id` INTEGER NOT NULL, FOREIGN KEY (`lot_id` ) REFERENCES `Lots`(`lot_id` ), FOREIGN KEY (`transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) )
What is the total share of transactions?
SELECT sum(share_count) FROM TRANSACTIONS
1
tracking_share_transactions
CREATE TABLE `Investors` ( `investor_id` INTEGER PRIMARY KEY, `Investor_details` VARCHAR(255) ); CREATE TABLE `Lots` ( `lot_id` INTEGER PRIMARY KEY, `investor_id` INTEGER NOT NULL, `lot_details` VARCHAR(255), FOREIGN KEY (`investor_id` ) REFERENCES `Investors`(`investor_id` ) ); CREATE TABLE `Ref_Transaction_Types` ( `transaction_type_code` VARCHAR(10) PRIMARY KEY, `transaction_type_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Transactions` ( `transaction_id` INTEGER PRIMARY KEY, `investor_id` INTEGER NOT NULL, `transaction_type_code` VARCHAR(10) NOT NULL, `date_of_transaction` DATETIME, `amount_of_transaction` DECIMAL(19,4), `share_count` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`investor_id` ) REFERENCES `Investors`(`investor_id` ),FOREIGN KEY (`transaction_type_code` ) REFERENCES `Ref_Transaction_Types`(`transaction_type_code` ) ); CREATE TABLE `Sales` ( `sales_transaction_id` INTEGER PRIMARY KEY, `sales_details` VARCHAR(255), FOREIGN KEY (`sales_transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) ); CREATE TABLE `Purchases` ( `purchase_transaction_id` INTEGER NOT NULL, `purchase_details` VARCHAR(255) NOT NULL, FOREIGN KEY (`purchase_transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) ); CREATE TABLE `Transactions_Lots` ( `transaction_id` INTEGER NOT NULL, `lot_id` INTEGER NOT NULL, FOREIGN KEY (`lot_id` ) REFERENCES `Lots`(`lot_id` ), FOREIGN KEY (`transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) )
Show all transaction ids with transaction code 'PUR'.
SELECT transaction_id FROM TRANSACTIONS WHERE transaction_type_code = 'PUR'
1
tracking_share_transactions
CREATE TABLE `Investors` ( `investor_id` INTEGER PRIMARY KEY, `Investor_details` VARCHAR(255) ); CREATE TABLE `Lots` ( `lot_id` INTEGER PRIMARY KEY, `investor_id` INTEGER NOT NULL, `lot_details` VARCHAR(255), FOREIGN KEY (`investor_id` ) REFERENCES `Investors`(`investor_id` ) ); CREATE TABLE `Ref_Transaction_Types` ( `transaction_type_code` VARCHAR(10) PRIMARY KEY, `transaction_type_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Transactions` ( `transaction_id` INTEGER PRIMARY KEY, `investor_id` INTEGER NOT NULL, `transaction_type_code` VARCHAR(10) NOT NULL, `date_of_transaction` DATETIME, `amount_of_transaction` DECIMAL(19,4), `share_count` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`investor_id` ) REFERENCES `Investors`(`investor_id` ),FOREIGN KEY (`transaction_type_code` ) REFERENCES `Ref_Transaction_Types`(`transaction_type_code` ) ); CREATE TABLE `Sales` ( `sales_transaction_id` INTEGER PRIMARY KEY, `sales_details` VARCHAR(255), FOREIGN KEY (`sales_transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) ); CREATE TABLE `Purchases` ( `purchase_transaction_id` INTEGER NOT NULL, `purchase_details` VARCHAR(255) NOT NULL, FOREIGN KEY (`purchase_transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) ); CREATE TABLE `Transactions_Lots` ( `transaction_id` INTEGER NOT NULL, `lot_id` INTEGER NOT NULL, FOREIGN KEY (`lot_id` ) REFERENCES `Lots`(`lot_id` ), FOREIGN KEY (`transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) )
Show all dates of transactions whose type code is "SALE".
SELECT date_of_transaction FROM TRANSACTIONS WHERE transaction_type_code = "SALE"
1
tracking_share_transactions
CREATE TABLE `Investors` ( `investor_id` INTEGER PRIMARY KEY, `Investor_details` VARCHAR(255) ); CREATE TABLE `Lots` ( `lot_id` INTEGER PRIMARY KEY, `investor_id` INTEGER NOT NULL, `lot_details` VARCHAR(255), FOREIGN KEY (`investor_id` ) REFERENCES `Investors`(`investor_id` ) ); CREATE TABLE `Ref_Transaction_Types` ( `transaction_type_code` VARCHAR(10) PRIMARY KEY, `transaction_type_description` VARCHAR(80) NOT NULL ); CREATE TABLE `Transactions` ( `transaction_id` INTEGER PRIMARY KEY, `investor_id` INTEGER NOT NULL, `transaction_type_code` VARCHAR(10) NOT NULL, `date_of_transaction` DATETIME, `amount_of_transaction` DECIMAL(19,4), `share_count` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`investor_id` ) REFERENCES `Investors`(`investor_id` ),FOREIGN KEY (`transaction_type_code` ) REFERENCES `Ref_Transaction_Types`(`transaction_type_code` ) ); CREATE TABLE `Sales` ( `sales_transaction_id` INTEGER PRIMARY KEY, `sales_details` VARCHAR(255), FOREIGN KEY (`sales_transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) ); CREATE TABLE `Purchases` ( `purchase_transaction_id` INTEGER NOT NULL, `purchase_details` VARCHAR(255) NOT NULL, FOREIGN KEY (`purchase_transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) ); CREATE TABLE `Transactions_Lots` ( `transaction_id` INTEGER NOT NULL, `lot_id` INTEGER NOT NULL, FOREIGN KEY (`lot_id` ) REFERENCES `Lots`(`lot_id` ), FOREIGN KEY (`transaction_id` ) REFERENCES `Transactions`(`transaction_id` ) )
Show the average amount of transactions with type code "SALE".
SELECT avg(amount_of_transaction) FROM TRANSACTIONS WHERE transaction_type_code = "SALE"