database_id
stringlengths
4
31
query
stringlengths
22
577
question
stringlengths
19
224
allergy_1
SELECT min(age) , avg(age) , max(age) FROM Student
What is the minimum, mean, and maximum age across all students?
allergy_1
SELECT LName FROM Student WHERE age = (SELECT min(age) FROM Student)
Provide the last name of the youngest student.
allergy_1
SELECT StuID FROM Student WHERE age = (SELECT max(age) FROM Student)
What student id corresponds to the oldest student?
allergy_1
SELECT major , count(*) FROM Student GROUP BY major
How many students are there for each major?
allergy_1
SELECT major FROM Student GROUP BY major ORDER BY count(*) DESC LIMIT 1
What is the largest major?
allergy_1
SELECT age , count(*) FROM Student GROUP BY age
How old is each student and how many students are each age?
allergy_1
SELECT avg(age) , sex FROM Student GROUP BY sex
What are the average ages for male and female students?
allergy_1
SELECT city_code , count(*) FROM Student GROUP BY city_code
How many students live in each city?
allergy_1
SELECT advisor , count(*) FROM Student GROUP BY advisor
How many students does each advisor have?
allergy_1
SELECT advisor FROM Student GROUP BY advisor ORDER BY count(*) DESC LIMIT 1
Give the advisor with the most students.
allergy_1
SELECT count(*) FROM Has_allergy WHERE Allergy = "Cat"
How many students are affected by cat allergies?
allergy_1
SELECT StuID FROM Has_allergy GROUP BY StuID HAVING count(*) >= 2
What are the students ids of students who have more than one allergy?
allergy_1
SELECT StuID FROM Student EXCEPT SELECT StuID FROM Has_allergy
Which students are unaffected by allergies?
allergy_1
SELECT count(*) FROM has_allergy AS T1 JOIN Student AS T2 ON T1.StuID = T2.StuID WHERE T2.sex = "F" AND (T1.allergy = "Milk" OR T1.allergy = "Eggs")
How many students who are female are allergic to milk or eggs?
allergy_1
SELECT count(*) FROM Has_allergy AS T1 JOIN Allergy_type AS T2 ON T1.allergy = T2.allergy WHERE T2.allergytype = "food"
How many students are affected by food related allergies?
allergy_1
SELECT Allergy FROM Has_allergy GROUP BY Allergy ORDER BY count(*) DESC LIMIT 1
Which allergy is the most common?
allergy_1
SELECT Allergy , count(*) FROM Has_allergy GROUP BY Allergy
How many students have each different allergy?
allergy_1
SELECT T2.allergytype , count(*) FROM Has_allergy AS T1 JOIN Allergy_type AS T2 ON T1.allergy = T2.allergy GROUP BY T2.allergytype
How many students are affected by each allergy type?
allergy_1
SELECT lname , age FROM Student WHERE StuID IN (SELECT StuID FROM Has_allergy WHERE Allergy = "Milk" INTERSECT SELECT StuID FROM Has_allergy WHERE Allergy = "Cat")
What are the last names and ages of the students who are allergic to milk and cat?
allergy_1
SELECT T1.Allergy , T1.AllergyType FROM Allergy_type AS T1 JOIN Has_allergy AS T2 ON T1.Allergy = T2.Allergy JOIN Student AS T3 ON T3.StuID = T2.StuID WHERE T3.Fname = "Lisa" ORDER BY T1.Allergy
What are the allergies the girl named Lisa has? And what are the types of them? Order the result by allergy names.
allergy_1
SELECT fname , sex FROM Student WHERE StuID IN (SELECT StuID FROM Has_allergy WHERE Allergy = "Milk" EXCEPT SELECT StuID FROM Has_allergy WHERE Allergy = "Cat")
What are the first name and gender of the students who have allergy to milk but can put up with cats?
allergy_1
SELECT avg(age) FROM Student WHERE StuID IN ( SELECT T1.StuID FROM Has_allergy AS T1 JOIN Allergy_Type AS T2 ON T1.Allergy = T2.Allergy WHERE T2.allergytype = "food" INTERSECT SELECT T1.StuID FROM Has_allergy AS T1 JOIN Allergy_Type AS T2 ON T1.Allergy = T2.Allergy WHERE T2.allergytype = "animal")
How old are the students with allergies to food and animal types on average?
allergy_1
SELECT fname , lname FROM Student WHERE StuID NOT IN (SELECT T1.StuID FROM Has_allergy AS T1 JOIN Allergy_Type AS T2 ON T1.Allergy = T2.Allergy WHERE T2.allergytype = "food")
What is the full name of each student who is not allergic to any type of food.
allergy_1
SELECT count(*) FROM Student WHERE sex = "M" AND StuID IN (SELECT StuID FROM Has_allergy AS T1 JOIN Allergy_Type AS T2 ON T1.Allergy = T2.Allergy WHERE T2.allergytype = "food")
How many male students (sex is 'M') are allergic to any type of food?
allergy_1
SELECT DISTINCT T1.fname , T1.city_code FROM Student AS T1 JOIN Has_Allergy AS T2 ON T1.stuid = T2.stuid WHERE T2.Allergy = "Milk" OR T2.Allergy = "Cat"
What are the distinct first names and cities of the students who have allergy either to milk or to cat?
allergy_1
SELECT count(*) FROM Student WHERE age > 18 AND StuID NOT IN ( SELECT StuID FROM Has_allergy AS T1 JOIN Allergy_Type AS T2 ON T1.Allergy = T2.Allergy WHERE T2.allergytype = "food" OR T2.allergytype = "animal")
How many students are over 18 and do not have allergy to food type or animal type?
allergy_1
SELECT fname , major FROM Student WHERE StuID NOT IN (SELECT StuID FROM Has_allergy WHERE Allergy = "Soy")
What are the first name and major of the students who are able to consume soy?
customers_and_addresses
SELECT customer_name FROM customers
What are the names of all the customers?
customers_and_addresses
SELECT count(*) FROM customers
Return the total number of distinct customers.
customers_and_addresses
SELECT avg(order_quantity) FROM order_items
Find the average order quantity per order.
customers_and_addresses
SELECT customer_name FROM customers WHERE payment_method = "Cash"
Which customers use "Cash" for payment method? Return the customer names.
customers_and_addresses
SELECT date_became_customer FROM customers WHERE customer_id BETWEEN 10 AND 20
What are the dates when customers with ids between 10 and 20 became customers?
customers_and_addresses
SELECT payment_method FROM customers GROUP BY payment_method ORDER BY count(*) DESC LIMIT 1
Find the payment method that is used most frequently.
customers_and_addresses
SELECT customer_name FROM customers WHERE payment_method = (SELECT payment_method FROM customers GROUP BY payment_method ORDER BY count(*) DESC LIMIT 1)
Find the name of the customers who use the most frequently used payment method.
customers_and_addresses
SELECT DISTINCT payment_method FROM customers
Return all the distinct payment methods used by customers.
customers_and_addresses
SELECT DISTINCT product_details FROM products
Return the the details of all products.
customers_and_addresses
SELECT customer_name FROM customers WHERE customer_name LIKE "%Alex%"
Which customer's name contains "Alex"? Find the full name.
customers_and_addresses
SELECT product_details FROM products WHERE product_details LIKE "%Latte%" OR product_details LIKE "%Americano%"
Which product's detail contains the word "Latte" or "Americano"? Return the full detail.
customers_and_addresses
SELECT t3.address_content FROM customers AS t1 JOIN customer_addresses AS t2 ON t1.customer_id = t2.customer_id JOIN addresses AS t3 ON t2.address_id = t3.address_id WHERE t1.customer_name = "Maudie Kertzmann"
Return the address content for the customer whose name is "Maudie Kertzmann".
customers_and_addresses
SELECT count(*) FROM customers AS t1 JOIN customer_addresses AS t2 ON t1.customer_id = t2.customer_id JOIN addresses AS t3 ON t2.address_id = t3.address_id WHERE t3.city = "Lake Geovannyton"
Find the number of customers who live in the city called Lake Geovannyton.
customers_and_addresses
SELECT t1.customer_name FROM customers AS t1 JOIN customer_addresses AS t2 ON t1.customer_id = t2.customer_id JOIN addresses AS t3 ON t2.address_id = t3.address_id WHERE t3.state_province_county = "Colorado"
What are the names of customers who live in Colorado state?
customers_and_addresses
SELECT city FROM addresses WHERE city NOT IN ( SELECT DISTINCT t3.city FROM customers AS t1 JOIN customer_addresses AS t2 ON t1.customer_id = t2.customer_id JOIN addresses AS t3 ON t2.address_id = t3.address_id)
What are the cities no customers live in?
customers_and_addresses
SELECT t3.city FROM customers AS t1 JOIN customer_addresses AS t2 ON t1.customer_id = t2.customer_id JOIN addresses AS t3 ON t2.address_id = t3.address_id GROUP BY t3.city ORDER BY count(*) DESC LIMIT 1
Find the city where the most customers live.
customers_and_addresses
SELECT DISTINCT city FROM addresses
List all the distinct cities
customers_and_addresses
SELECT city FROM addresses WHERE zip_postcode = 255
Which city is post code 255 located in?
customers_and_addresses
SELECT state_province_county , country FROM addresses WHERE zip_postcode LIKE "4%"
What are the state and country of all the cities that have post codes starting with 4.\
customers_and_addresses
SELECT country FROM addresses GROUP BY country HAVING count(address_id) > 4
For which countries are there more than four distinct addresses listed?
customers_and_addresses
SELECT channel_code FROM customer_contact_channels GROUP BY channel_code HAVING count(customer_id) < 5
Which contact channel codes were used less than 5 times?
customers_and_addresses
SELECT DISTINCT channel_code FROM customers AS t1 JOIN customer_contact_channels AS t2 ON t1.customer_id = t2.customer_id WHERE t1.customer_name = "Tillman Ernser"
Find the contact channel code that was used by the customer named "Tillman Ernser".
customers_and_addresses
SELECT max(t2.active_to_date) FROM customers AS t1 JOIN customer_contact_channels AS t2 ON t1.customer_id = t2.customer_id WHERE t1.customer_name = "Tillman Ernser"
Return the the "active to date" of the latest contact channel used by the customer named "Tillman Ernser".
customers_and_addresses
SELECT avg(active_to_date - active_from_date) FROM customer_contact_channels
Compute the average active time span of contact channels.
customers_and_addresses
SELECT channel_code , contact_number FROM customer_contact_channels WHERE active_to_date - active_from_date = (SELECT active_to_date - active_from_date FROM customer_contact_channels ORDER BY (active_to_date - active_from_date) DESC LIMIT 1)
Return the channel code and contact number of the customer contact channel whose active duration was the longest.
customers_and_addresses
SELECT t1.customer_name , t2.active_from_date FROM customers AS t1 JOIN customer_contact_channels AS t2 ON t1.customer_id = t2.customer_id WHERE t2.channel_code = 'Email'
What are the name and active date of the customers whose contact channel code is email?
customers_and_addresses
SELECT t1.customer_name FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id JOIN order_items AS t3 ON t2.order_id = t3.order_id WHERE t3.order_quantity = ( SELECT max(order_quantity) FROM order_items)
Find the name of the customer who made the order of the largest amount of goods.
customers_and_addresses
SELECT t1.customer_name FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id JOIN order_items AS t3 ON t2.order_id = t3.order_id GROUP BY t1.customer_name ORDER BY sum(t3.order_quantity) DESC LIMIT 1
Give me the name of the customer who ordered the most items in total.
customers_and_addresses
SELECT t1.payment_method FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id JOIN order_items AS t3 ON t2.order_id = t3.order_id GROUP BY t1.customer_name ORDER BY sum(t3.order_quantity) LIMIT 1
Tell me the payment method used by the customer who ordered the least amount of goods in total.
customers_and_addresses
SELECT count(DISTINCT product_id) FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id JOIN order_items AS t3 ON t2.order_id = t3.order_id WHERE t1.customer_name = "Rodrick Heaney"
Find the number of distinct products Rodrick Heaney has bought so far.
customers_and_addresses
SELECT sum(t3.order_quantity) FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id JOIN order_items AS t3 ON t2.order_id = t3.order_id WHERE t1.customer_name = "Rodrick Heaney"
Tell me the total quantity of products bought by the customer called "Rodrick Heaney".
customers_and_addresses
SELECT count(DISTINCT customer_id) FROM customer_orders WHERE order_status = "Cancelled"
Return the number of customers who have at least one order with "Cancelled" status.
customers_and_addresses
SELECT count(*) FROM customer_orders WHERE order_details = "Second time"
Tell me the number of orders with "Second time" as order detail.
customers_and_addresses
SELECT t1.customer_name , t2.order_date FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id WHERE order_status = "Delivered"
What are the customer name and date of the orders whose status is "Delivered".
customers_and_addresses
SELECT sum(t2.order_quantity) FROM customer_orders AS t1 JOIN order_items AS t2 ON t1.order_id = t2.order_id WHERE t1.order_status = "Cancelled"
Find the total quantity of products associated with the orders in the "Cancelled" status.
customers_and_addresses
SELECT sum(t2.order_quantity) FROM customer_orders AS t1 JOIN order_items AS t2 ON t1.order_id = t2.order_id WHERE t1.order_date < '2018-03-17 07:13:53'
What is the total amount of products purchased before 2018-03-17 07:13:53?
customers_and_addresses
SELECT t1.customer_name FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id ORDER BY t2.order_date DESC LIMIT 1
Find the name of the customer who made an order most recently.
customers_and_addresses
SELECT t2.product_details FROM order_items AS t1 JOIN products AS t2 ON t1.product_id = t2.product_id GROUP BY t1.product_id ORDER BY count(*) DESC LIMIT 1
What is the most frequently ordered product? Tell me the detail of the product
customers_and_addresses
SELECT t2.product_details , t2.product_id FROM order_items AS t1 JOIN products AS t2 ON t1.product_id = t2.product_id GROUP BY t1.product_id ORDER BY sum(t1.order_quantity) LIMIT 1
What are the name and ID of the product bought the most.
customers_and_addresses
SELECT address_content FROM addresses WHERE city = "East Julianaside" AND state_province_county = "Texas" UNION SELECT address_content FROM addresses WHERE city = "Gleasonmouth" AND state_province_county = "Arizona"
What are all the addresses in East Julianaside, Texas or in Gleasonmouth, Arizona.
customers_and_addresses
SELECT customer_name FROM customers WHERE payment_method ! = 'Cash'
What is the name of customers who do not use Cash as payment method.
customers_and_addresses
SELECT customer_name FROM customers EXCEPT SELECT t1.customer_name FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id JOIN order_items AS t3 ON t2.order_id = t3.order_id JOIN products AS t4 ON t3.product_id = t4.product_id WHERE product_details = 'Latte'
What are names of customers who never ordered product Latte.
customers_and_addresses
SELECT customer_name FROM customers EXCEPT SELECT t1.customer_name FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id
What are the names of customers who never made an order.
customers_and_addresses
SELECT t1.customer_name FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id JOIN order_items AS t3 ON t2.order_id = t3.order_id JOIN products AS t4 ON t3.product_id = t4.product_id WHERE product_details = 'Latte' INTERSECT SELECT t1.customer_name FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id JOIN order_items AS t3 ON t2.order_id = t3.order_id JOIN products AS t4 ON t3.product_id = t4.product_id WHERE product_details = 'Americano'
What are the names of customers who have purchased both products Latte and Americano?
hr_1
SELECT T1.first_name , T2.department_name FROM employees AS T1 JOIN departments AS T2 ON T1.department_id = T2.department_id
What are the first name and department name of all employees?
hr_1
SELECT first_name , last_name , salary FROM employees WHERE salary < 6000
What are the full names and salaries for any employees earning less than 6000?
hr_1
SELECT first_name , department_id FROM employees WHERE last_name = 'McEwen'
What are the first names and department numbers for employees with last name McEwen?
hr_1
SELECT * FROM departments WHERE department_name = 'Marketing'
What is all the information about the Marketing department?
hr_1
SELECT hire_date FROM employees WHERE first_name NOT LIKE '%M%'
On what dates were employees without the letter M in their first names hired?
hr_1
SELECT first_name , last_name , hire_date , salary , department_id FROM employees WHERE first_name NOT LIKE '%M%'
What are the full name, hire date, salary, and department id for employees without the letter M in their first name?
hr_1
SELECT first_name , last_name , hire_date , salary , department_id FROM employees WHERE first_name NOT LIKE '%M%' ORDER BY department_id
What are the full name, hire data, salary and department id for employees without the letter M in their first name, ordered by ascending department id?
hr_1
SELECT phone_number FROM employees WHERE salary BETWEEN 8000 AND 12000
Return the phone numbers of employees with salaries between 8000 and 12000.
hr_1
SELECT first_name , last_name , salary FROM employees WHERE first_name LIKE '%m'
Return the full names and salaries for employees with first names that end with the letter m.
hr_1
SELECT job_id , hire_date FROM employees WHERE hire_date BETWEEN '2007-11-05' AND '2009-07-05'
What are the job ids and dates of hire for employees hired after November 5th, 2007 and before July 5th, 2009?
hr_1
SELECT first_name , last_name FROM employees WHERE department_id = 70 OR department_id = 90
What are the full names of employees who with in department 70 or 90?
hr_1
SELECT * FROM employees WHERE hire_date < '2002-06-21'
What is all the information about employees hired before June 21, 2002?
hr_1
SELECT * FROM employees WHERE first_name LIKE '%D%' OR first_name LIKE '%S%' OR first_name LIKE '%N%' ORDER BY salary DESC
What is all the information about employees with D, S, or N in their first name, ordered by salary descending?
hr_1
SELECT * FROM employees WHERE hire_date > '1987-09-07'
Which employees were hired after September 7th, 1987?
hr_1
SELECT job_title FROM jobs WHERE min_salary > 9000
Which job titles correspond to jobs with salaries over 9000?
hr_1
SELECT job_title , max_salary - min_salary FROM jobs WHERE max_salary BETWEEN 12000 AND 18000
What are the job titles, and range of salaries for jobs with maximum salary between 12000 and 18000?
hr_1
SELECT employee_id , MAX(end_date) FROM job_history GROUP BY employee_id
What are the employee ids for each employee and final dates of employment at their last job?
hr_1
SELECT department_id FROM employees GROUP BY department_id HAVING COUNT(commission_pct) > 10
What are the department ids for which more than 10 employees had a commission?
hr_1
SELECT DISTINCT department_id FROM employees GROUP BY department_id , manager_id HAVING COUNT(employee_id) >= 4
What are department ids for departments with managers managing more than 3 employees?
hr_1
SELECT country_id , COUNT(*) FROM locations GROUP BY country_id
Give the country id and corresponding count of cities in each country.
hr_1
SELECT job_id FROM job_history WHERE end_date - start_date > 300 GROUP BY job_id HAVING COUNT(*) >= 2
What are the job ids for jobs done more than once for a period of more than 300 days?
hr_1
SELECT employee_id FROM job_history GROUP BY employee_id HAVING COUNT(*) >= 2
What are the employee ids for employees who have held two or more jobs?
hr_1
SELECT employee_id , country_name FROM employees AS T1 JOIN departments AS T2 ON T1.department_id = T2.department_id JOIN locations AS T3 ON T2.location_id = T3.location_id JOIN countries AS T4 ON T3.country_id = T4.country_id
What are all the employee ids and the names of the countries in which they work?
hr_1
SELECT T2.department_name , COUNT(*) FROM employees AS T1 JOIN departments AS T2 ON T1.department_id = T2.department_id GROUP BY T2.department_name
Give the name of each department and the number of employees in each.
hr_1
SELECT job_title , AVG(salary) FROM employees AS T1 JOIN jobs AS T2 ON T1.job_id = T2.job_id GROUP BY T2.job_title
What is the average salary for each job title?
hr_1
SELECT first_name , last_name FROM employees WHERE salary > (SELECT salary FROM employees WHERE employee_id = 163 )
Provide the full names of employees earning more than the employee with id 163.
hr_1
SELECT MIN(salary) , department_id FROM employees GROUP BY department_id
What is the minimum salary in each department?
hr_1
SELECT first_name , last_name , department_id FROM employees WHERE salary IN (SELECT MIN(salary) FROM employees GROUP BY department_id)
What are the full names and department ids for the lowest paid employees across all departments.
hr_1
SELECT employee_id FROM employees WHERE salary > (SELECT AVG(salary) FROM employees)
What are the employee ids for employees who make more than the average?