db_id
stringclasses
68 values
question
stringlengths
24
325
evidence
stringlengths
0
580
SQL
stringlengths
23
728
sales
Count the total quantity for sales from id 1 to 10.
sales from id 1 to 10 refers to SalesID BETWEEN 1 AND 10;
SELECT SUM(Quantity) FROM Sales WHERE SalesID BETWEEN 1 AND 10
sales
Calculate the average quantity per sales from sales id 20 to 30.
average quantity = AVG(Quantity); SalesID BETWEEN 20 AND 30;
SELECT AVG(Quantity) FROM Sales WHERE SalesID BETWEEN 20 AND 30
sales
List down the product id for products with the highest quantity.
highest quantity refers to MAX(Quantity);
SELECT DISTINCT ProductID FROM Sales WHERE Quantity = ( SELECT MAX(Quantity) FROM Sales )
sales
How many product ids have the lowest price?
lowest price refers to MIN(Price);
SELECT COUNT(DISTINCT ProductID) FROM Products WHERE Price = ( SELECT MAX(Price) FROM Products )
sales
List down product names of free gifts.
free gifts refers to Price = 0;
SELECT Name FROM Products WHERE Price = 0
sales
List down the product name for products from id 1 to 10.
products from id 1 to 10 refers to ProductID BETWEEN 1 AND 10;
SELECT Name FROM Products WHERE ProductID BETWEEN 1 AND 10
sales
What is the name of the product with the lowest quantity?
lowest quantity refers to MIN(Quantity);
SELECT T2.Name FROM Sales AS T1 INNER JOIN Products AS T2 ON T1.ProductID = T2.ProductID ORDER BY T1.Quantity LIMIT 1
sales
How many customer ids have purchased Hex Nut 9?
Hex Nut 9' is name of product;
SELECT COUNT(T1.CustomerID) FROM Sales AS T1 INNER JOIN Products AS T2 ON T1.ProductID = T2.ProductID WHERE T2.Name = 'Hex Nut 9'
sales
Calculate the total sales ids that were sales of Flat Washer 8.
Flat Washer 8' is name of product;
SELECT COUNT(T1.SalesID) FROM Sales AS T1 INNER JOIN Products AS T2 ON T1.ProductID = T2.ProductID WHERE T2.Name = 'Flat Washer 8'
sales
List down all of the product names that were placed by sales person with id 10.
id refers to SalesPersonID; SalesPersonID = 10
SELECT DISTINCT T1.Name FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID WHERE T2.SalesPersonID = 10
sales
List down the first name of customers who placed order for product id 1.
SELECT T1.FirstName FROM Customers AS T1 INNER JOIN Sales AS T2 ON T1.CustomerID = T2.CustomerID INNER JOIN Products AS T3 ON T2.ProductID = T3.ProductID WHERE T2.ProductID = 1
sales
What is the last name of the customer who placed an order for sales id 178?
SELECT T1.LastName FROM Customers AS T1 INNER JOIN Sales AS T2 ON T1.CustomerID = T2.CustomerID WHERE T2.SalesID = 178
sales
List down product ids that were purchased by customers called Abby.
SELECT DISTINCT T1.ProductID FROM Sales AS T1 INNER JOIN Customers AS T2 ON T1.CustomerID = T2.CustomerID WHERE T2.FirstName = 'Abby'
sales
Write down all of the product ids that were placed by Meander.
SELECT DISTINCT T2.ProductID FROM Employees AS T1 INNER JOIN Sales AS T2 ON T1.EmployeeID = T2.SalesPersonID WHERE T1.FirstName = 'Meander'
sales
What is the last name of sales person for sales id 100?
SELECT T1.LastName FROM Employees AS T1 INNER JOIN Sales AS T2 ON T1.EmployeeID = T2.SalesPersonID WHERE T2.SalesID = 100
sales
What is the first name of employee who handled sales for customer called Abigail?
SELECT DISTINCT T3.FirstName FROM Customers AS T1 INNER JOIN Sales AS T2 ON T1.CustomerID = T2.CustomerID INNER JOIN Employees AS T3 ON T2.SalesPersonID = T3.EmployeeID WHERE T1.FirstName = 'Abigail'
sales
How many free gifts have customer with id 11782 received?
free gifts refers to Price = 0;
SELECT COUNT(T1.ProductID) FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID WHERE T2.CustomerID = 11782 AND T1.Price = 0
sales
What is the full name of customers who dealt with sales person with id 5?
full name = FirstName, MiddleInitial, LastName;
SELECT T1.FirstName, T1.MiddleInitial, T1.LastName FROM Customers AS T1 INNER JOIN Sales AS T2 ON T1.CustomerID = T2.CustomerID WHERE T2.SalesPersonID = 5
sales
Among customers with IDs from 1 to 100, what is the highest price of products they purchased?
IDs from 1 to 100 refers to CustomerID BETWEEN 1 AND 100 ; highest price refers to MAX(Price);
SELECT T1.Price FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID WHERE T2.CustomerID BETWEEN 1 AND 100 ORDER BY T1.Price DESC LIMIT 1
sales
Calculate the total price of products purchased by Adam.
total price = SUM(MULTIPLY(Price, Quantity));
SELECT SUM(T3.Price * T2.quantity) FROM Customers AS T1 INNER JOIN Sales AS T2 ON T1.CustomerID = T2.CustomerID INNER JOIN Products AS T3 ON T2.ProductID = T3.ProductID WHERE T1.FirstName = 'Adam'
sales
Calculate the total price for products from id 400 to 500.
total price = SUM(MULTIPLY(Price, Quantity)); from id 400 to 500 refers to ProductID BETWEEN 400 AND 500;
SELECT SUM(T1.Price * T2.quantity) FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID WHERE T1.ProductID BETWEEN 400 AND 500
sales
Calculate the total quantity of products with name starting with alphabet "c".
name starting with alphabet "c" refers to Name LIKE 'C%';
SELECT SUM(T2.Quantity) FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID WHERE SUBSTR(T1.Name, 1, 1) = 'C'
sales
Calculate the total quantity of products purchased by customer called Adrian.
SELECT SUM(T2.Quantity) FROM Customers AS T1 INNER JOIN Sales AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.FirstName = 'Adam'
sales
List the product ID of the top five products, by descending order, in terms of price.
top 5 products in terms of Price refers to MAX(Price) LIMIT 5;
SELECT ProductID FROM Products ORDER BY Price DESC LIMIT 5
sales
Among the products, how many of them are freebies?
freebies refers to Price = 0;
SELECT COUNT(ProductID) FROM Products WHERE Price = 0
sales
Write down the name of products whose sale quantity is more than 950.
quantity is more than 950 refers to Quantity > 950;
SELECT DISTINCT T1.Name FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID WHERE T2.Quantity > 950
sales
What is the full name of employee who sold 1000 units?
full name of employee = FirstName, MiddleInitial, LastName; units refers to quantity; Quantity = 100
SELECT DISTINCT T2.FirstName, T2.MiddleInitial, T2.LastName FROM Sales AS T1 INNER JOIN Employees AS T2 ON T1.SalesPersonID = T2.EmployeeID WHERE T1.Quantity = 1000
sales
Tally the product name and quantity of the first ten sales.
first ten sales refers to SalesID BETWEEN 1 AND 10;
SELECT T3.Name, T2.Quantity FROM Customers AS T1 INNER JOIN Sales AS T2 ON T1.CustomerID = T2.CustomerID INNER JOIN Products AS T3 ON T2.ProductID = T3.ProductID WHERE T2.SalesID BETWEEN 1 AND 10
sales
What is the total sales amount for Reflector?
total sales amount = SUM(MULTIPLY(Price, Quantity)); 'Reflector' is name of product;
SELECT SUM(T1.Price * T2.quantity) FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID WHERE T1.Name = 'Reflector'
sales
What is the difference in price between HL Mountain Frame - Black, 42 and LL Mountain Frame - Black, 42?
difference = SUBTRACT((Price WHERE Name = 'HL Mountain Frame - Black, 42'), (Price WHERE Name = 'HL Mountain Frame - Black, 42'));
SELECT ( SELECT Price FROM Products WHERE Name = 'HL Mountain Frame - Black, 42' ) - ( SELECT Price FROM Products WHERE Name = 'LL Mountain Frame - Black, 42' ) AS num
sales
Calculate the total number of sales closed by Michel E. DeFrance?
SELECT COUNT(T1.SalesID) FROM Sales AS T1 INNER JOIN Employees AS T2 ON T1.SalesPersonID = T2.EmployeeID WHERE T2.FirstName = 'Michel' AND T2.MiddleInitial = 'e' AND T2.LastName = 'DeFrance'
sales
What is the average number of customers per sales person?
average = DIVIDE(COUNT(CustomerID), COUNT(EmployeeID));
SELECT CAST(COUNT(T1.CustomerID) AS REAL) / COUNT(T3.EmployeeID) FROM Customers AS T1 INNER JOIN Sales AS T2 ON T1.CustomerID = T2.CustomerID INNER JOIN Employees AS T3 ON T2.SalesPersonID = T3.EmployeeID
sales
Among all customers handled by Innes E. del Castillo, how many have purchased Short-Sleeve Classic Jersey, L?
Short-Sleeve Classic Jersey, L' is name of product;
SELECT COUNT(T2.CustomerID) FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID INNER JOIN Employees AS T3 ON T2.SalesPersonID = T3.EmployeeID WHERE T3.FirstName = 'Innes' AND T3.LastName = 'del Castillo' AND T1.Name = 'Short-Sleeve Classic Jersey, L' AND T3.MiddleInitial = 'e'
sales
Name the sales person who helped Elizabeth A. White to purchase Road-250 Black, 48.
name of the sales person = FirstName, MiddleInitial, LastName; 'Road-250 Black, 48' is name of product;
SELECT DISTINCT T3.FirstName, T3.MiddleInitial, T3.LastName FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID INNER JOIN Employees AS T3 ON T2.SalesPersonID = T3.EmployeeID INNER JOIN Customers AS T4 ON T2.CustomerID = T4.CustomerID WHERE T4.MiddleInitial = 'A' AND T4.LastName = 'White' AND T1.Name = 'Road-250 Black, 48' AND T4.FirstName = 'Elizabeth'
sales
How many sales people managed to sell Headlights - Weatherproof?
Headlights - Weatherproof' is name of product
SELECT COUNT(T2.SalesPersonID) FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID WHERE T1.Name = 'Headlights - Weatherproof'
sales
Calculate the revenue produced through sales of HL Road Frame - Red, 56.
revenue = MULTIPLY(SUM(Quantity, Price)); 'HL Road Frame - Red, 56' is name of product;
SELECT SUM(T2.Quantity * T1.Price) FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID WHERE T1.Name = 'HL Road Frame - Red, 56'
sales
How many sales transactions were given by the customer named Joe L. Lopez?
sales transactions refers to SalesID;
SELECT COUNT(T1.SalesID) FROM Sales AS T1 INNER JOIN Customers AS T2 ON T1.CustomerID = T2.CustomerID WHERE T2.FirstName = 'Joe' AND T2.MiddleInitial = 'L' AND T2.LastName = 'Lopez'
sales
Name the customers who received 'Touring Rim' as a free gift.
name of the customer = FirstName, MiddleInitial, LastName; 'Touring Rim' is name of product;
SELECT DISTINCT T1.FirstName, T1.MiddleInitial, T1.LastName FROM Customers AS T1 INNER JOIN Sales AS T2 ON T1.CustomerID = T2.CustomerID INNER JOIN Products AS T3 ON T2.ProductID = T3.ProductID WHERE T3.Name = 'Touring Rim' AND T3.Price = 0
sales
Find the number of customers handled by each of the sales people.
SELECT COUNT(CustomerID) FROM Sales GROUP BY SalesPersonID
sales
How many sales people are handling all the customers?
SELECT COUNT(EmployeeID) FROM Employees
sales
Identify the name of the sales person with employee ID 7.
name of the sales person = FirstName, MiddleInitial, LastName;
SELECT FirstName, MiddleInitial, LastName FROM Employees WHERE EmployeeID = 7
sales
Name the most expensive and the least expensive products available, excluding free gifts.
most expensive product refers to MAX(Price); least expensive product refers to MIN(Price); excluding free gifts refers to not including Price = 0;
SELECT Name FROM Products WHERE Price IN (( SELECT MAX(Price) FROM Products ), ( SELECT MIN(Price) FROM Products ))
sales
How many customers have the first name Abigail?
SELECT COUNT(CustomerID) FROM Customers WHERE FirstName = 'Abigail'
sales
Indicate the quantity of Blade products sold.
Blade' is name of product;
SELECT DISTINCT T2.Quantity FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID WHERE T1.Name = 'Blade'
sales
Give the full name of the employee who has sold the most quantity.
full name of the employee = FirstName, LastName; most quantity refers to MAX(Quantity);
SELECT T1.FirstName, T1.LastName FROM Employees AS T1 INNER JOIN Sales AS T2 ON T1.EmployeeID = T2.SalesPersonID ORDER BY T2.Quantity DESC LIMIT 1
sales
List the full name of the customer who purchased the most quantity of products.
full name of the customer = FirstName, LastName; most quantity refers to MAX(Quantity);
SELECT T1.FirstName, T1.LastName FROM Customers AS T1 INNER JOIN Sales AS T2 ON T1.CustomerID = T2.CustomerID ORDER BY T2.Quantity DESC LIMIT 1
sales
What is the name of the product that is most sold by sale person id 20?
most sold refers to MAX(Quantity);
SELECT T1.Name FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID WHERE T2.SalesPersonID = 20 ORDER BY T2.Quantity DESC LIMIT 1
sales
List the first names of employees with trading quantity for more than 500.
trading quantity for more than 500 refers to Quantity > 500;
SELECT DISTINCT T1.FirstName FROM Employees AS T1 INNER JOIN Sales AS T2 ON T1.EmployeeID = T2.SalesPersonID WHERE T2.Quantity > 500
sales
List the first names of customers who have purchased products from sale person id 1.
SELECT T1.FirstName FROM Customers AS T1 INNER JOIN Sales AS T2 ON T1.CustomerID = T2.CustomerID WHERE T2.SalesPersonID = 1
sales
Calculate the total trading quantity of Abraham sold to Aaron Alexander.
total trading quantity = SUM(Quantity WHERE Employees.FirstName = 'Abraham' AND Customers.FirstName = 'Aaron' AND Customers.LastName = 'Alexander');
SELECT SUM(T2.Quantity) FROM Customers AS T1 INNER JOIN Sales AS T2 ON T1.CustomerID = T2.CustomerID INNER JOIN Employees AS T3 ON T2.SalesPersonID = T3.EmployeeID WHERE T2.SalesPersonID = 1 AND T1.FirstName = 'Aaron' AND T1.LastName = 'Alexander' AND T3.FirstName = 'Abraham'
sales
List the full names of customers who have purchased products in quantity over 600.
full names of customers = FirstName, LastName; quantity over 600 refers to quantity > 600;
SELECT T1.FirstName, T1.LastName FROM Customers AS T1 INNER JOIN Sales AS T2 ON T1.CustomerID = T2.CustomerID WHERE T2.Quantity > 600
sales
Among the customers whose first name is Cameron, who bought the product in the most quantity?
most quantity refers to MAX(Quantity); who refers to FirstName, LastName;
SELECT T1.FirstName, T1.LastName FROM Customers AS T1 INNER JOIN Sales AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.FirstName = 'Cameron' ORDER BY T2.Quantity DESC LIMIT 1
sales
Please provide sales ID for products named Hex Nut with a price greater than 100.
price greater than 100 refers to price > 100;
SELECT T2.SalesID FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID WHERE T1.Name LIKE 'Hex Nut%' AND T1.Price > 100
sales
Identify customer IDs who bought products priced from 1000 to 2000.
priced from 1000 to 2000 refers to Price BETWEEN 1000 AND 2000;
SELECT DISTINCT T2.CustomerID FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID WHERE T1.Price BETWEEN 1000 AND 2000
sales
Calculate the total quantity of products that are gifts.
total quantity = SUM(Quantity); gifts refers to Price = 0;
SELECT SUM(T2.Quantity) FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID WHERE T1.Price = 0
sales
How many of the employees have the last name "Ringer" ?
SELECT COUNT(LastName) FROM Employees WHERE LastName = 'Ringer'
sales
Among the products with product ID lower than 15, how many of them costs 10 and below?
product ID lower than 15 refers to ProductID < 15; costs 10 and below refers to Price; Price < = 10;
SELECT COUNT(ProductID) FROM Products WHERE ProductID < 15 AND Price <= 10
sales
Give the product's name brought by Aaron Alexander.
SELECT DISTINCT T1.Name FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID INNER JOIN Customers AS T3 ON T2.CustomerID = T3.CustomerID WHERE T3.FirstName = 'Aaron' AND T3.LastName = 'Alexander'
sales
Give the product ID and name of the product with the highest prices among the quantity ranges from 400 to 500.
highest prices refers to MAX(Price); quantity ranges from 400 to 500 refers to Quantity BETWEEN 400 AND 500;
SELECT T1.ProductID, T1.Name FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID WHERE T2.quantity BETWEEN 400 AND 500 ORDER BY T1.Price DESC LIMIT 1
sales
Among customers named Kate, who has the highest quantity?
highest quantity refers to MAX(Quantity);
SELECT T2.FirstName, T2.LastName FROM Sales AS T1 INNER JOIN Customers AS T2 ON T1.CustomerID = T2.CustomerID WHERE T2.FirstName = 'Kate' ORDER BY T1.Quantity DESC LIMIT 1
sales
Among the products that have price ranges from 100 to 150, what is the customer ID and sales ID of the product with a quantity lower than 25?
price ranges from 100 to 150 refers to Price BETWEEN 100 AND 150; quantity lower than 25 refers to Quantity < 25;
SELECT T2.CustomerID, T2.SalesID FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID WHERE T1.Price BETWEEN 100 AND 150 AND T2.Quantity < 25
sales
In sales with a quantity of 60, how many of them have a price not greater than 500?
SELECT COUNT(T1.ProductID) FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID WHERE T2.quantity = 60 AND T1.Price <= 500
sales
In customers with the first name of Erica, how many of them bought a quantity below 200?
quantity below 200 refers to quantity < 200;
SELECT COUNT(T1.ProductID) FROM Sales AS T1 INNER JOIN Customers AS T2 ON T1.CustomerID = T2.CustomerID WHERE T2.FirstName = 'Erica' AND T1.Quantity < 200
sales
What is the price and quantity of the product named Seat Tube?
SELECT DISTINCT T2.Price, T1.Quantity FROM Sales AS T1 INNER JOIN Products AS T2 ON T1.ProductID = T2.ProductID WHERE T2.Name = 'Seat Tube'
sales
List the sales ID of the product with a quantity of 590 and named "External Lock Washer 7".
External Lock Washer 7' is name of product;
SELECT T1.SalesID FROM Sales AS T1 INNER JOIN Products AS T2 ON T1.ProductID = T2.ProductID WHERE T2.Name = 'External Lock Washer 7' AND T1.Quantity = 590
sales
In sales ID between 30 and 40, who is the customer that bought a total quantity of 403?
who refers to FirstName, LastName;
SELECT T2.FirstName, T2.LastName FROM Sales AS T1 INNER JOIN Customers AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Quantity = 403 AND T1.SalesID BETWEEN 30 AND 40
sales
List the customer's ID and last name of the customer that purchased a product with a quantity greater than 90% of the average quantity of all listed products.
quantity greater than 90% of the average quantity = Quantity > MULTIPLY(AVG(Quantity), 0.9);
SELECT T2.CustomerID, T2.LastName FROM Sales AS T1 INNER JOIN Customers AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Quantity > ( SELECT AVG(Quantity) FROM Sales ) * 0.9
sales
What is the name of the most expensive product?
most expensive product refers to MAX(Price);
SELECT Name FROM Products WHERE Price = ( SELECT MAX(Price) FROM Products )
sales
How many customers are named Madison?
SELECT COUNT(CustomerID) FROM Customers WHERE FirstName = 'Madison'
sales
How many types of "HL Touring Frames" are there?
types of HL Touring Frames refers to Name like '%HL Touring Frame%';
SELECT COUNT(ProductID) FROM Products WHERE Name LIKE '%HL Touring Frame%'
sales
How many customers share the most common last name?
most common last name refers to MAX(COUNT(LastName));
SELECT COUNT(CustomerID) FROM Customers GROUP BY LastName ORDER BY COUNT(LastName) DESC LIMIT 1
sales
How many free or gift products are there?
free gift refers to Price = 0;
SELECT COUNT(ProductID) FROM Products WHERE Price = 0
sales
What is the name of the sales person who handled the highest number of sales?
name of the sales person = FirstName, MiddleInitial, LastName; highest number of sales refers to MAX(COUNT(SalesID));
SELECT T1.FirstName, T1.MiddleInitial, T1.LastName FROM Employees AS T1 INNER JOIN Sales AS T2 ON T2.SalesPersonID = T1.EmployeeID GROUP BY T2.SalesPersonID, T1.FirstName, T1.MiddleInitial, T1.LastName ORDER BY COUNT(T2.SalesID) DESC LIMIT 1
sales
What is the full name of the customer who purchased the highest amount of total price in a single purchase?
full name of the customer = FirstName, MiddleInitial, LastName; highest amount of total price refers to MAX(MULTIPLY(Quantity, Price));
SELECT T2.FirstName, T2.MiddleInitial, T2.LastName FROM Sales AS T1 INNER JOIN Customers AS T2 ON T1.CustomerID = T2.CustomerID INNER JOIN Products AS T3 ON T1.ProductID = T3.ProductID GROUP BY T1.SalesID, T1.Quantity, T3.Price, FirstName, MiddleInitial, LastName ORDER BY T1.Quantity * T3.Price DESC LIMIT 1
sales
How many "Mountain-500 Black 42" were sold in total?
Mountain-500 Black 42' is name of product; sold in total = SUM(Quantity);
SELECT SUM(T2.Quantity) FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID WHERE T1.Name = 'Mountain-500 Black, 42'
sales
How much is the total amount of sales handled by Heather McBadden?
total amount of sales = SUM(MULTIPLY(Quantity, Price));
SELECT SUM(T2.Quantity * T3.Price) FROM Employees AS T1 INNER JOIN Sales AS T2 ON T1.EmployeeID = T2.SalesPersonID INNER JOIN Products AS T3 ON T2.ProductID = T3.ProductID WHERE T1.FirstName = 'Heather' AND T1.LastName = 'McBadden'
sales
How many "Mountain-100 Silver, 38" were sold by Stearns MacFeather?
Mountain-100 Silver, 38' is name of product;
SELECT SUM(T2.Quantity) FROM Employees AS T1 INNER JOIN Sales AS T2 ON T1.EmployeeID = T2.SalesPersonID INNER JOIN Products AS T3 ON T2.ProductID = T3.ProductID WHERE T1.FirstName = 'Stearns' AND T1.LastName = 'MacFeather' AND T3.Name = 'Mountain-100 Silver, 38'
sales
How many type of products did Dalton M. Coleman purchase?
SELECT COUNT(T2.ProductID) FROM Customers AS T1 INNER JOIN Sales AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.FirstName = 'Dalton' AND T1.MiddleInitial = 'M' AND T1.LastName = 'Coleman'
sales
What are the full names of the top 3 employees who handled the highest number of sales?
full names of employees = FirstName, MiddleInitital, LastName; highest number of sales refers to MAX(COUNT(SalesID));
SELECT T1.FirstName, T1.MiddleInitial, T1.LastName FROM Employees AS T1 INNER JOIN Sales AS T2 ON T1.EmployeeID = T2.SalesPersonID GROUP BY T2.SalesPersonID, T1.FirstName, T1.MiddleInitial, T1.LastName ORDER BY COUNT(T2.SalesID) DESC LIMIT 3
sales
Among the "Mountain-500 Black" product types, which type was purchased the most?
Mountain-500 Black product types refers to Name like 'Mountain-500 Black%'; purchased the most refers to MAX(SUM(Quantity));
SELECT T1.Name FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID WHERE T1.Name LIKE 'Mountain-500 Black%' GROUP BY T2.Quantity, T1.Name ORDER BY SUM(T2.Quantity) DESC LIMIT 1
sales
How many employees sold "ML Road Frame-W - Yellow, 40"?
ML Road Frame-W - Yellow, 40' is name of product;
SELECT COUNT(T2.SalesPersonID) FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID WHERE T1.Name = 'ML Road Frame-W - Yellow, 40'
sales
How many chainring bolts were sold under sales ID 551971?
Chainring Bolts' is name of product;
SELECT T1.Quantity FROM Sales AS T1 INNER JOIN Products AS T2 ON T1.ProductID = T2.ProductID WHERE T2.Name = 'Chainring Bolts' AND T1.SalesID = 551971
sales
How many employees sold over 20,000 quantities of "Touring-2000 Blue, 50"?
over 20,000 quantities refers to Quantity > 20000; 'Touring-2000 Blue, 50' is name of product;
SELECT COUNT(*) FROM ( SELECT SUM(Quantity) FROM Sales WHERE ProductID IN ( SELECT ProductID FROM Products WHERE Name = 'Touring-2000 Blue, 50' ) GROUP BY Quantity, SalesPersonID HAVING SUM(Quantity) > 20000 )
sales
What is the total cost of all the "Road-650, Red, 60" products that Abraham E. Bennet sold?
total cost = SUM(MULTIPLY(Quantity, Price)); 'Road-650, Red, 60' is name of product;
SELECT SUM(T2.Quantity * T3.Price) FROM Employees AS T1 INNER JOIN Sales AS T2 ON T1.EmployeeID = T2.SalesPersonID INNER JOIN Products AS T3 ON T2.ProductID = T3.ProductID WHERE T1.FirstName = 'Abraham' AND T1.MiddleInitial = 'e' AND T1.LastName = 'Bennet' AND T3.Name = 'Road-650 Red, 60'
sales
Which product has the highest total amount of quantity sold? Calculate its overall total price.
highest total amount of quantity refers to MAX(Quantity); overall total price = SUM(MULTIPLY(Quantity, Price));
SELECT T1.Name, SUM(T2.Quantity * T1.Price) FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID GROUP BY T1.ProductID, T1.Name ORDER BY SUM(T2.Quantity) DESC LIMIT 1
sales
List the first name of all the customers whose last name is Chen.
SELECT FirstName, LastName FROM Customers WHERE LastName = 'Chen'
sales
Among the employee names, what is the most common middle initial?
most common middle initial refers to MAX(COUNT(MiddleInitial));
SELECT MiddleInitial FROM Employees GROUP BY MiddleInitial ORDER BY COUNT(MiddleInitial) DESC LIMIT 1
sales
What is the average price of products that cost between 100 and 200?
average price = DIVIDE(SUM(Price, COUNT(Price))); cost refers to Price; Price BETWEEN 100 AND 200;
SELECT AVG(Price) FROM Products WHERE Price BETWEEN 100 AND 200
sales
Give the full name of the customer who bought the most amount of products.
full name of the customer = FirstName, MiddleInitial, LastName; most amount of products refers to MAX(MULTIPLY(Quantity, Price));
SELECT T3.FirstName, T3.MiddleInitial, T3.LastName FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID INNER JOIN Customers AS T3 ON T2.CustomerID = T3.CustomerID ORDER BY T2.Quantity * T1.Price DESC LIMIT 1
sales
Of the employees who sold Blade, who has the most amount of sales?
Blade' is name of product; most amount of sales refers to MAX(MULTIPLY(Quantity, Price));
SELECT T1.FirstName, T1.MiddleInitial, T1.LastName FROM Employees AS T1 INNER JOIN Sales AS T2 ON T1.EmployeeID = T2.SalesPersonID INNER JOIN Products AS T3 ON T2.ProductID = T3.ProductID ORDER BY T2.Quantity * T3.Price DESC LIMIT 1
sales
List the full name of customers who spend more than 50,000 in descending order the amount spend.
full name of the customer = FirstName, MiddleInitial, LastName; more than 50,000 in the amount refers to MULTIPLY(Quantity, Price) > 50000;
SELECT DISTINCT T3.FirstName, T3.MiddleInitial, T3.LastName FROM Products AS T1 INNER JOIN Sales AS T2 ON T1.ProductID = T2.ProductID INNER JOIN Customers AS T3 ON T2.CustomerID = T3.CustomerID WHERE T2.Quantity * T1.Price > 50000
sales
Name the product that sold the most quantity.
most quantity refers to MAX(Quantity);
SELECT T2.Name FROM Sales AS T1 INNER JOIN Products AS T2 ON T1.ProductID = T2.ProductID ORDER BY T1.Quantity DESC LIMIT 1
sales
Find and list the products that sold below the average quantity.
below the average quantity refers to Quantity < AVG(Quantity);
SELECT DISTINCT T2.Name FROM Sales AS T1 INNER JOIN Products AS T2 ON T1.ProductID = T2.ProductID WHERE T1.Quantity < ( SELECT AVG(Quantity) FROM Sales )
menu
How many dishes do not have correct data for the year in which it appeared first?
do not have correct data refers to first_appeared < 1851 or first_appeared > 2012;
SELECT COUNT(*) FROM Dish WHERE first_appeared < 1851 OR first_appeared > 2012
menu
Which dish lasted longer, Anchovies or Fresh lobsters in every style?
if (SUBTRACT(last_appeared, first_appeared) WHERE name = 'Anchovies') > (SUBTRACT(last_appeared, first_appeared) WHERE name = 'Fresh lobsters in every style'), it means 'Anchovies' lasted longer; if (SUBTRACT(last_appeared , first_appeared) WHERE name = 'Fresh lobsters in every style') > (SUBTRACT(last_appeared , first_appeared) WHERE name = 'Anchovies') it means 'Fresh lobsters in every style' last longer;
SELECT CASE WHEN SUM(CASE WHEN name = 'Anchovies' THEN last_appeared - first_appeared ELSE 0 END) - SUM(CASE WHEN name = 'Fresh lobsters in every style' THEN last_appeared - first_appeared ELSE 0 END) > 0 THEN 'Anchovies' ELSE 'Fresh lobsters in every style' END FROM Dish WHERE name IN ('Fresh lobsters in every style', 'Anchovies')
menu
Among all the dishes that were once free, what is the name of the dish that had appeared on most menus?
dishes that were once free refers to lowest_price = 0; appeared on most menus refers to MAX(menus_appeared);
SELECT name FROM Dish WHERE lowest_price = 0 ORDER BY menus_appeared DESC LIMIT 1
menu
How many menus with the name "Waldorf Astoria" have 4 pages?
4 pages refers to page_count = 4;
SELECT COUNT(*) FROM Menu WHERE name = 'Waldorf Astoria' AND page_count = 4
menu
Please list the prices of the dish "Clear green turtle" on every menu page it appeared on.
Clear green turtle is a name of dish;
SELECT T2.price FROM Dish AS T1 INNER JOIN MenuItem AS T2 ON T1.id = T2.dish_id WHERE T1.name = 'Clear green turtle'
menu
Among all the menu pages with the appearance of the dish "Clear green turtle", how many of them have the dish at a stable price?
Clear green turtle is a name of dish; stable price refers to highest_price is null;
SELECT SUM(CASE WHEN T1.name = 'Clear green turtle' THEN 1 ELSE 0 END) FROM Dish AS T1 INNER JOIN MenuItem AS T2 ON T1.id = T2.dish_id WHERE T1.highest_price IS NULL
menu
Please list the IDs of all the menus in which the dish "Clear green turtle" had appeared.
Clear green turtle is a name of dish;
SELECT T1.menu_id FROM MenuPage AS T1 INNER JOIN MenuItem AS T2 ON T1.id = T2.menu_page_id INNER JOIN Dish AS T3 ON T2.dish_id = T3.id WHERE T3.name = 'Clear green turtle'