problem
stringlengths 121
422
| db_id
stringclasses 69
values | solution
stringlengths 23
804
|
---|---|---|
Write SQL query to solve given problem: How many male patients have been described as immune to quadrivalent HPV?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | synthea | SELECT COUNT(DISTINCT T1.patient) FROM patients AS T1 INNER JOIN immunizations AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'HPV quadrivalent' AND T1.gender = 'M' |
Write SQL query to solve given problem: Indicate the start date of patient Walter Bahringer's care plan.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | synthea | SELECT DISTINCT T2.start FROM patients AS T1 INNER JOIN careplans AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Walter' AND T1.last = 'Bahringer' |
Write SQL query to solve given problem: Describe the care plans of patient Major D'Amore's plan of care.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | synthea | SELECT DISTINCT T2.DESCRIPTION FROM patients AS T1 INNER JOIN careplans AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Major' AND T1.last = 'D''Amore' |
Write SQL query to solve given problem: Calculate the percentage of male patients with viral sinusitis condition.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | synthea | SELECT CAST(SUM(CASE WHEN T1.gender = 'M' THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(T1.patient) FROM patients AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Viral sinusitis (disorder)' |
Write SQL query to solve given problem: Among the patients who have been using Penicillin V Potassium 250 MG, what percentage of patients are female?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | synthea | SELECT CAST(SUM(CASE WHEN T1.gender = 'F' THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(T1.patient) FROM patients AS T1 INNER JOIN medications AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Penicillin V Potassium 250 MG' |
Write SQL query to solve given problem: Among the white patients, what is the average body height of the patients?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | synthea | SELECT AVG(T1.VALUE) FROM observations AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.race = 'white' AND T1.DESCRIPTION = 'Body Height' |
Write SQL query to solve given problem: Indicate the care plan needed for the patient living at 179 Sydni Roads, Taunton, MA 02780 US.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | synthea | SELECT T1.DESCRIPTION FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.address = '179 Sydni Roads Taunton MA 02780 US' |
Write SQL query to solve given problem: Provide the allergen of the Dominican patient named Dirk Languish.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | synthea | SELECT T1.DESCRIPTION FROM allergies AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.first = 'Dirk' AND T2.last = 'Langosh' AND T2.ethnicity = 'dominican' |
Write SQL query to solve given problem: How many patients who are allergic to peanuts have asthma?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | synthea | SELECT COUNT(DISTINCT T2.patient) FROM conditions AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient INNER JOIN allergies AS T3 ON T2.patient = T3.PATIENT WHERE T1.DESCRIPTION = 'Asthma' AND T3.DESCRIPTION = 'Allergy to peanuts' |
Write SQL query to solve given problem: Who is the 44-year-old patient diagnosed with drug overdose?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | synthea | SELECT T2.first, T2.last FROM conditions AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.DESCRIPTION = 'Drug overdose' AND ROUND((strftime('%J', T2.deathdate) - strftime('%J', T2.birthdate)) / 365) = 44 |
Write SQL query to solve given problem: Provide the social security number of the patient with the highest systolic blood pressure.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | synthea | SELECT T2.ssn FROM observations AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.DESCRIPTION = 'Systolic Blood Pressure' ORDER BY T1.VALUE DESC LIMIT 1 |
Write SQL query to solve given problem: What is the care plan description of the prevalent disease with the highest prevalence percentage?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | synthea | SELECT T4.DESCRIPTION FROM all_prevalences AS T1 INNER JOIN conditions AS T2 ON T2.DESCRIPTION = T1.ITEM INNER JOIN encounters AS T3 ON T2.ENCOUNTER = T3.ID INNER JOIN careplans AS T4 ON T4.ENCOUNTER = T3.ID ORDER BY T1."PREVALENCE PERCENTAGE" DESC LIMIT 1 |
Write SQL query to solve given problem: What is the care plan for the patient with social security number 999-15-3685?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | synthea | SELECT DISTINCT T1.DESCRIPTION FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.ssn = '999-15-3685' |
Write SQL query to solve given problem: Calculate the average age of the male patients that have hypertension.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | synthea | SELECT SUM(CASE WHEN T2.deathdate IS NULL THEN ROUND((strftime('%J', date('now')) - strftime('%J', T2.birthdate)) / 365) ELSE ROUND((strftime('%J', T2.deathdate) - strftime('%J', T2.birthdate)) / 365) END) / COUNT(T2.patient) FROM conditions AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.DESCRIPTION = 'Hypertension' AND T2.gender = 'M' |
Write SQL query to solve given problem: List 5 patients' name that need medication due to streptococcal sore throat disorder.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | synthea | SELECT DISTINCT T2.first, T2.last FROM medications AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.REASONDESCRIPTION = 'Streptococcal sore throat (disorder)' LIMIT 5 |
Write SQL query to solve given problem: Who is the patient with a body weight of 61.97 kg?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | synthea | SELECT T2.first, T2.last FROM observations AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.DESCRIPTION = 'Body Weight' AND T1.UNITS = 'kg' AND T1.VALUE = 61.97 |
Write SQL query to solve given problem: Among the male patients, list down 5 birth dates of patients taking the medication "Penicillin V Potassium 250 MG".. Keep the solution inside sql tag ```sql [SQL-Query] ``` | synthea | SELECT DISTINCT T2.birthdate FROM medications AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.DESCRIPTION = 'Penicillin V Potassium 250 MG' AND T2.gender = 'M' LIMIT 5 |
Write SQL query to solve given problem: List down the full name of Irish patients diagnosed with the prevalent diseases that have an occurrence greater than the 96% of the average occurrences of all conditions.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | synthea | SELECT DISTINCT T2.first, T2.last FROM conditions AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient INNER JOIN all_prevalences AS T3 ON T1.DESCRIPTION = T3.ITEM WHERE T2.ethnicity = 'irish' AND 100 * CAST(T3.OCCURRENCES AS REAL) / ( SELECT AVG(OCCURRENCES) FROM all_prevalences ) > 96 |
Write SQL query to solve given problem: What is the difference between the number of married patients and the number of single patients with diabetes?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | synthea | SELECT SUM(CASE WHEN T2.marital = 'M' THEN 1 ELSE 0 END) - SUM(CASE WHEN T2.marital = 'S' THEN 1 ELSE 0 END) FROM conditions AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.DESCRIPTION = 'Diabetes' |
Write SQL query to solve given problem: List the country and how many customers are there.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT country, COUNT(customerNumber) FROM customers GROUP BY country |
Write SQL query to solve given problem: Which different vendor has the most amount of orders? Calculate the total estimated earnings.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT DISTINCT T1.productVendor, T1.MSRP - T1.buyPrice FROM products AS T1 INNER JOIN orderdetails AS T2 ON T1.productCode = T2.productCode GROUP BY T1.productVendor, T1.MSRP, T1.buyPrice ORDER BY COUNT(T2.quantityOrdered) DESC LIMIT 1 |
Write SQL query to solve given problem: Who is the sales agent of the distinct customer who paid the highest amount in the year 2004?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT DISTINCT T3.lastName, T3.firstName FROM payments AS T1 INNER JOIN customers AS T2 ON T1.customerNumber = T2.customerNumber INNER JOIN employees AS T3 ON T2.salesRepEmployeeNumber = T3.employeeNumber WHERE STRFTIME('%Y', T1.paymentDate) = '2004' ORDER BY T1.amount DESC LIMIT 1 |
Write SQL query to solve given problem: What was the total price of the products shipped to Rovelli Gifts Distributors Ltd. between 1/1/2003 and 12/31/2003?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T3.priceEach * T3.quantityOrdered FROM customers AS T1 INNER JOIN orders AS T2 ON T1.customerNumber = T2.customerNumber INNER JOIN orderdetails AS T3 ON T2.orderNumber = T3.orderNumber WHERE T1.customerName = 'Rovelli Gifts' AND T2.status = 'Shipped' AND STRFTIME('%Y', T2.shippedDate) = '2003' |
Write SQL query to solve given problem: How many employees are there in Sydney?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT COUNT(employeeNumber) FROM employees WHERE officeCode = ( SELECT officeCode FROM offices WHERE city = 'Sydney' ) |
Write SQL query to solve given problem: Which sales representatives in New York city whose leader is Anthony Bow with the employee number is 1143? Indicate their employee numbers.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T1.employeeNumber FROM employees AS T1 INNER JOIN offices AS T2 ON T1.officeCode = T2.officeCode WHERE T1.reportsTo = 1143 AND T2.city = 'NYC' |
Write SQL query to solve given problem: What is the average, highest and lowest annual payments collected between 1/1/2003 to 12/31/2005?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT CAST(SUM(T1.amount) AS REAL) / 3, MAX(T1.amount) , MIN(T1.amount) FROM payments AS T1 INNER JOIN customers AS T2 ON T1.customerNumber = T2.customerNumber WHERE T1.paymentDate BETWEEN '2003-01-01' AND '2005-12-31' |
Write SQL query to solve given problem: Which countries do the top 5 highest paying customers in a single payment come from? Indicate their entire address.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT DISTINCT T2.country, T2.addressLine1, T2.addressLine2 FROM payments AS T1 INNER JOIN customers AS T2 ON T1.customerNumber = T2.customerNumber ORDER BY T1.amount DESC LIMIT 5 |
Write SQL query to solve given problem: How many checks were issued by Euro+ Shopping Channel in the year 2004?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT COUNT(T1.checkNumber) FROM payments AS T1 INNER JOIN customers AS T2 ON T1.customerNumber = T2.customerNumber WHERE customerName = 'Euro+ Shopping Channel' AND STRFTIME('%Y', T1.paymentDate) = '2004' |
Write SQL query to solve given problem: Of all the classic cars, with a product scale of 1:18, which product is the most ordered product by customers?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T1.productName FROM products AS T1 INNER JOIN orderdetails AS T2 ON T1.productCode = T2.productCode WHERE T1.productScale = '1:18' AND T1.productLine = 'Classic Cars' GROUP BY T1.productName ORDER BY SUM(T2.quantityOrdered) DESC LIMIT 1 |
Write SQL query to solve given problem: How many customers have a credit limit of not more than 100,000 and which customer made the highest total payment amount for the year 2004?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT ( SELECT COUNT(customerNumber) FROM customers WHERE creditLimit <= 100000 AND customerNumber IN ( SELECT customerNumber FROM payments WHERE STRFTIME('%Y', paymentDate) = '2004' ) ), T1.customerName FROM customers AS T1 INNER JOIN payments AS T2 ON T1.customerNumber = T2.customerNumber WHERE T1.creditLimit <= 100000 AND STRFTIME('%Y', T2.paymentDate) = '2004' GROUP BY T1.customerNumber, T1.customerName ORDER BY SUM(T2.amount) DESC LIMIT 1 |
Write SQL query to solve given problem: Which of the customers, whose Tokyo-based sales representative reports to the Vice President of Sales whose employee number is 1056, has paid the highest payment? List the customer's name, the contact person and calculate the total amount of that customer's total payments.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T2.customerName, T2.contactFirstName, T2.contactLastName, SUM(T3.amount) FROM employees AS T1 INNER JOIN customers AS T2 ON T2.salesRepEmployeeNumber = T1.employeeNumber INNER JOIN payments AS T3 ON T2.customerNumber = T3.customerNumber INNER JOIN offices AS T4 ON T1.officeCode = T4.officeCode WHERE T4.city = 'Tokyo' AND T1.reportsTo = 1056 GROUP BY T2.customerName, T2.contactFirstName, T2.contactLastName ORDER BY amount DESC LIMIT 1 |
Write SQL query to solve given problem: Which two products has the highest and lowest expected profits? Determine the total price for each product in terms of the largest quantity that was ordered.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T2.productName, SUM(T1.quantityOrdered * T1.priceEach) FROM orderdetails AS T1 INNER JOIN ( SELECT productCode, productName FROM products ORDER BY MSRP - buyPrice DESC LIMIT 1 ) AS T2 ON T1.productCode = T2.productCode UNION SELECT T2.productName, SUM(quantityOrdered * priceEach) FROM orderdetails AS T1 INNER JOIN ( SELECT productCode, productName FROM products ORDER BY MSRP - buyPrice ASC LIMIT 1 ) AS T2 ON T1.productCode = T2.productCode |
Write SQL query to solve given problem: How many different orders with a total price greater than 4000 are cancelled?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT COUNT(DISTINCT T1.orderNumber) FROM orderdetails AS T1 INNER JOIN orders AS T2 ON T1.orderNumber = T2.orderNumber WHERE T1.quantityOrdered * T1.priceEach > 4000 AND T2.status = 'Cancelled' |
Write SQL query to solve given problem: How many distinct orders were there in 2003 when the quantity ordered was less than 30?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT COUNT(DISTINCT T1.orderNumber) FROM orderdetails AS T1 INNER JOIN orders AS T2 ON T1.orderNumber = T2.orderNumber WHERE T1.quantityOrdered < 30 AND STRFTIME('%Y', T2.orderDate) = '2003' |
Write SQL query to solve given problem: What is the total value of cancelled orders?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT SUM(T1.quantityOrdered * T1.priceEach) FROM orderdetails AS T1 INNER JOIN orders AS T2 ON T1.orderNumber = T2.orderNumber WHERE T2.status = 'Cancelled' |
Write SQL query to solve given problem: Please calculate the total value of Motorcycles orders.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT SUM(T1.quantityOrdered * T1.priceEach) FROM orderdetails AS T1 INNER JOIN products AS T2 ON T1.productCode = T2.productCode WHERE T2.productLine = 'Motorcycles' |
Write SQL query to solve given problem: How many Planes orders were there?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT COUNT(T1.productCode) FROM orderdetails AS T1 INNER JOIN products AS T2 ON T1.productCode = T2.productCode WHERE T2.productLine = 'Planes' |
Write SQL query to solve given problem: How many orders which expected profits greater than 100?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT COUNT(T1.productCode) FROM orderdetails AS T1 INNER JOIN products AS T2 ON T1.productCode = T2.productCode WHERE T2.MSRP - T2.buyPrice > 100 |
Write SQL query to solve given problem: Please calculate the average total price of orders from Exoto Designs Vendor in 2005.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT SUM(T2.quantityOrdered * T2.priceEach) / COUNT(T3.orderNumber) FROM products AS T1 INNER JOIN orderdetails AS T2 ON T1.productCode = T2.productCode INNER JOIN orders AS T3 ON T2.orderNumber = T3.orderNumber WHERE T1.productVendor = 'Exoto Designs' AND STRFTIME('%Y', T3.orderDate) = '2005' |
Write SQL query to solve given problem: How many sales representatives who have office code is 1?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT COUNT(officeCode) FROM employees WHERE jobTitle = 'Sales Rep' AND officeCode = 1 |
Write SQL query to solve given problem: Please list different customer names with the payment amount of over 50,000.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT DISTINCT T2.customerName FROM payments AS T1 INNER JOIN customers AS T2 ON T1.customerNumber = T2.customerNumber WHERE T1.amount > 50000 |
Write SQL query to solve given problem: Please calculate the total payment amount of customers who come from the USA.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT SUM(T1.amount) FROM payments AS T1 INNER JOIN customers AS T2 ON T1.customerNumber = T2.customerNumber WHERE T2.country = 'USA' |
Write SQL query to solve given problem: What are the total payments of customers with no credit limit in 2003?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT SUM(amount) FROM payments WHERE STRFTIME('%Y', paymentDate) = '2003' AND customerNumber IN ( SELECT customerNumber FROM customers WHERE creditLimit = 0 ) |
Write SQL query to solve given problem: Please list the name and phone number of the customer whose order was cancelled.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T2.customerName, T2.phone FROM orders AS T1 INNER JOIN customers AS T2 ON T1.customerNumber = T2.customerNumber WHERE T1.status = 'Cancelled' |
Write SQL query to solve given problem: How many French customers shipped 2 orders which have been cancelled?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT COUNT(T2.country) FROM orders AS T1 INNER JOIN customers AS T2 ON T1.customerNumber = T2.customerNumber WHERE T1.status = 'Shipped' AND T2.country = 'France' GROUP BY T2.customerNumber HAVING COUNT(T1.status) = 2 |
Write SQL query to solve given problem: Please calculate the average total price of shipped orders from German customers.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT SUM(T3.quantityOrdered * T3.priceEach) / COUNT(T2.orderNumber) FROM customers AS T1 INNER JOIN orders AS T2 ON T1.customerNumber = T2.customerNumber INNER JOIN orderdetails AS T3 ON T2.orderNumber = T3.orderNumber WHERE T2.status = 'Shipped' AND T1.country = 'Germany' |
Write SQL query to solve given problem: List out full name of employees who are working in Tokyo?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T1.firstName, T1.lastName FROM employees AS T1 INNER JOIN offices AS T2 ON T1.officeCode = T2.officeCode WHERE T2.city = 'Tokyo' |
Write SQL query to solve given problem: How many Sales Rep who are working in Tokyo? List out email and full name of those employees.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T1.firstName, T1.lastName, T1.email FROM employees AS T1 INNER JOIN offices AS T2 ON T1.officeCode = T2.officeCode WHERE T2.city = 'Tokyo' AND T1.jobTitle = 'Sales Rep' |
Write SQL query to solve given problem: State the email of those who are staff of Murphy Diane whose number is 1002 and living in San Francisco. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T1.email FROM employees AS T1 INNER JOIN offices AS T2 ON T1.officeCode = T2.officeCode WHERE T1.reportsTo = 1002 AND T2.city = 'San Francisco' |
Write SQL query to solve given problem: Determine the email and Code of employee who are working at United State, state MA. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T1.email, T1.employeeNumber FROM employees AS T1 INNER JOIN offices AS T2 ON T1.officeCode = T2.officeCode WHERE T2.state = 'MA' AND T2.country = 'USA' |
Write SQL query to solve given problem: How many Sales Manager who are working in Sydney? List out their email.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T1.email FROM employees AS T1 INNER JOIN offices AS T2 ON T1.officeCode = T2.officeCode WHERE T1.jobTitle LIKE '%Sales Manager%' AND T2.city = 'Sydney' |
Write SQL query to solve given problem: How many employees who are living in Australia and have the credit limit under 200000? State their email address and countries where they are working.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T2.email, T3.country FROM customers AS T1 INNER JOIN employees AS T2 ON T1.salesRepEmployeeNumber = T2.employeeNumber INNER JOIN offices AS T3 ON T2.officeCode = T3.officeCode WHERE T3.country = 'Australia' AND T1.creditLimit < 200000 AND T2.jobTitle = 'Sales Rep' |
Write SQL query to solve given problem: State 10 emails of UK Sales Rep who have the lowest credit limit.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT DISTINCT T2.email FROM customers AS T1 INNER JOIN employees AS T2 ON T1.salesRepEmployeeNumber = T2.employeeNumber WHERE T2.jobTitle = 'Sales Rep' AND T1.country = 'UK' ORDER BY T1.creditLimit LIMIT 10 |
Write SQL query to solve given problem: How many Australian customers who have credit line under 220000?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT COUNT(creditLimit) FROM customers WHERE creditLimit < 220000 AND country = 'Australia' |
Write SQL query to solve given problem: List out 3 customer numbers who have highest amount payment. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT customerNumber FROM payments ORDER BY amount DESC LIMIT 3 |
Write SQL query to solve given problem: Determine the email and Code of employee who are working at United State, state CA. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T1.email, T1.employeeNumber FROM employees AS T1 INNER JOIN offices AS T2 ON T1.officeCode = T2.officeCode WHERE T2.country = 'USA' AND T2.state = 'CA' GROUP BY T1.email, T1.officeCode |
Write SQL query to solve given problem: List out full name of employees who are working in Boston?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T1.firstName, T1.lastName FROM employees AS T1 INNER JOIN offices AS T2 ON T1.officeCode = T2.officeCode WHERE T2.city = 'Boston' |
Write SQL query to solve given problem: State top 3 emails of UK Sales Rep who have the highest credit limit.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T2.email FROM customers AS T1 INNER JOIN employees AS T2 ON T1.salesRepEmployeeNumber = T2.employeeNumber WHERE T2.jobTitle = 'Sales Rep' AND T1.country = 'UK' GROUP BY T1.customerName, T2.email ORDER BY SUM(T1.creditLimit) DESC LIMIT 3 |
Write SQL query to solve given problem: How many customers who are in Norway and have credit line under 220000?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT COUNT(creditLimit) FROM customers WHERE creditLimit < 220000 AND country = 'Norway' |
Write SQL query to solve given problem: List out full name and email of employees who are working in Paris?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T1.firstName, T1.lastName, T1.email FROM employees AS T1 INNER JOIN offices AS T2 ON T1.officeCode = T2.officeCode WHERE T2.city = 'Paris' |
Write SQL query to solve given problem: List the product code of the top five motorcycles, by descending order, the number of quantity in stock.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT productCode, quantityInStock FROM products WHERE productLine = 'Motorcycles' ORDER BY quantityInStock DESC LIMIT 5 |
Write SQL query to solve given problem: Among the German customers, how many of the them has credit limit of zero?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT COUNT(customerNumber) FROM customers WHERE creditLimit = 0 AND country = 'Germany' |
Write SQL query to solve given problem: From 2003 to 2004, how many customers have paid more than three times?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT COUNT(customernumber) FROM ( SELECT customernumber FROM payments WHERE STRFTIME('%Y', paymentDate) >= '2003' AND STRFTIME('%Y', paymentDate) <= '2004' GROUP BY customernumber HAVING COUNT(customernumber) > 3 ) T |
Write SQL query to solve given problem: What is the average actual profit by 1937 Lincoln Berline?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT SUM(T1.priceEach - T2.buyPrice) / COUNT(*) FROM orderdetails AS T1 INNER JOIN products AS T2 ON T1.productCode = T2.productCode WHERE T2.productName = '1937 Lincoln Berline' |
Write SQL query to solve given problem: Among the motorcycles with product scale of 1:10, which of them is the most ordered by American customers?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T1.productName FROM products AS T1 INNER JOIN orderdetails AS T2 ON T1.productCode = T2.productCode INNER JOIN orders AS T3 ON T2.orderNumber = T3.orderNumber INNER JOIN customers AS T4 ON T3.customerNumber = T4.customerNumber WHERE T1.productLine = 'Motorcycles' AND T1.productScale = '1:10' AND T4.country = 'USA' GROUP BY T1.productName ORDER BY SUM(T2.quantityOrdered) DESC LIMIT 1 |
Write SQL query to solve given problem: Between 8/1/2003 and 8/30/2004, how many checks were issued by Mini Gifts Distributors Ltd.? Please list their check numbers.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T1.checkNumber FROM payments AS T1 INNER JOIN customers AS T2 ON T1.customerNumber = T2.customerNumber WHERE T1.paymentDate >= '2003-08-01' AND T1.paymentDate <= '2004-08-30' AND T2.customerName = 'Mini Gifts Distributors Ltd.' |
Write SQL query to solve given problem: For the planes which has the hightest total price, how much it exceeds the average?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT MAX(quantityOrdered * priceEach) - AVG(priceEach) FROM orderdetails WHERE productCode IN ( SELECT productCode FROM products WHERE productLine = 'Planes' ) |
Write SQL query to solve given problem: What is the total value of shipped vintage car orders from 2003-2004?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT SUM(T2.priceEach * T2.quantityOrdered) FROM products AS T1 INNER JOIN orderdetails AS T2 ON T1.productCode = T2.productCode INNER JOIN orders AS T3 ON T2.orderNumber = T3.orderNumber WHERE T3.status = 'Shipped' AND T3.orderDate BETWEEN '2003-01-01' AND '2004-12-31' |
Write SQL query to solve given problem: Who is the sales agent of the customer who has made the highest payment? Include the full names of employee and his/her supervisor.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T1.firstName, T1.lastName, T1.reportsTo FROM employees AS T1 INNER JOIN customers AS T2 ON T1.employeeNumber = T2.salesRepEmployeeNumber INNER JOIN payments AS T3 ON T2.customerNumber = T3.customerNumber ORDER BY T3.amount DESC LIMIT 1 |
Write SQL query to solve given problem: What is the highest amount of order made by the sales representative in Boston? Please give the name of the product and amount.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T2.productName, T1.quantityOrdered * T1.priceEach FROM orderdetails AS T1 INNER JOIN products AS T2 ON T1.productCode = T2.productCode INNER JOIN orders AS T3 ON T1.orderNumber = T3.orderNumber INNER JOIN customers AS T4 ON T3.customerNumber = T4.customerNumber WHERE T4.city = 'Boston' AND T4.salesRepEmployeeNumber IN ( SELECT employeeNumber FROM employees WHERE jobTitle = 'Sales Rep' ) ORDER BY T1.quantityOrdered DESC LIMIT 1 |
Write SQL query to solve given problem: What is the total actual profit gained from orders made by American customers from 2003-01-06 to 2005-05-09?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT SUM(T2.priceEach - T1.buyPrice) FROM products AS T1 INNER JOIN orderdetails AS T2 ON T1.productCode = T2.productCode INNER JOIN orders AS T3 ON T2.orderNumber = T3.orderNumber INNER JOIN customers AS T4 ON T3.customerNumber = T4.customerNumber WHERE T3.orderDate > '2003-01-05' AND T3.orderDate < '2005-05-10' |
Write SQL query to solve given problem: From which branch does the sales representative employee who made the most sales in 2005? Please indicates its full address and phone number.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T3.addressLine1, T3.addressLine2, T3.phone FROM orderdetails AS T1 INNER JOIN orders AS T2 ON T1.orderNumber = T2.orderNumber INNER JOIN customers AS T3 ON T2.customerNumber = T3.customerNumber INNER JOIN employees AS T4 ON T3.salesRepEmployeeNumber = T4.employeeNumber INNER JOIN offices AS T5 ON T4.officeCode = T5.officeCode WHERE STRFTIME('%Y', T2.orderDate) = '2005' AND T4.jobTitle = 'Sales Rep' ORDER BY T1.quantityOrdered DESC LIMIT 1 |
Write SQL query to solve given problem: What is the phone number of all companies where the last name of the contact person starts with the letter M and are not from Germany?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT phone FROM customers WHERE contactLastName LIKE 'M%' AND country != 'Germany' |
Write SQL query to solve given problem: Calculate the average amount of payments made by customers during the first half of 2004.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT AVG(amount) FROM payments WHERE paymentDate BETWEEN '2004-01-01' AND '2004-06-30' |
Write SQL query to solve given problem: Of all the orders placed and shipped throughout the year 2005, what percentage of those orders corresponds to customer number 186?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT CAST(SUM(CASE WHEN customerNumber = 186 THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(orderNumber) FROM orders WHERE status = 'Shipped' AND shippedDate BETWEEN '2005-01-01' AND '2005-12-31' |
Write SQL query to solve given problem: How many customers with a canceled shipment have a credit limit greater than 115,000?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT COUNT(T1.customerNumber) FROM customers AS T1 INNER JOIN orders AS T2 ON T1.customerNumber = T2.customerNumber WHERE T2.status = 'Cancelled' AND T1.creditLimit > 115000 |
Write SQL query to solve given problem: On what date did the customer with the lowest credit limit serviced by sales representative Barry Jones make payments for his/her orders?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T3.paymentDate FROM employees AS T1 INNER JOIN customers AS T2 ON T1.employeeNumber = T2.salesRepEmployeeNumber INNER JOIN payments AS T3 ON T2.customerNumber = T3.customerNumber WHERE T1.firstName = 'Barry' AND T1.lastName = 'Jones' AND T1.jobTitle = 'Sales Rep' ORDER BY T2.creditLimit ASC LIMIT 1 |
Write SQL query to solve given problem: To whom does the employee have to inform that is the sales representative of the French customer?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T1.reportsTo FROM employees AS T1 INNER JOIN customers AS T2 ON T1.employeeNumber = T2.salesRepEmployeeNumber WHERE T2.country = 'France' |
Write SQL query to solve given problem: What is the full address of the customer who commented that DHL be used for the order that was shipped on April 4, 2005?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T1.addressLine1, T1.addressLine2 FROM customers AS T1 INNER JOIN orders AS T2 ON T1.customerNumber = T2.customerNumber WHERE T2.shippedDate = '2005-04-04' AND T2.status = 'Shipped' |
Write SQL query to solve given problem: What is the full address of the office where the employee who is a sales representative for the customer whose business is located in the city of New York works?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T2.addressLine1, T2.addressLine2 FROM employees AS T1 INNER JOIN customers AS T2 ON T1.employeeNumber = T2.salesRepEmployeeNumber INNER JOIN offices AS T3 ON T1.officeCode = T3.officeCode WHERE T2.city = 'NYC' AND T1.jobTitle = 'Sales Rep' |
Write SQL query to solve given problem: What is the full address of the office where 4 people work and one of them is Sales Representation?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T1.addressLine1, T1.addressLine2 FROM customers AS T1 INNER JOIN employees AS T2 ON T1.salesRepEmployeeNumber = T2.employeeNumber WHERE T2.jobTitle = 'Sales Rep' |
Write SQL query to solve given problem: What profit can the seller Carousel DieCast Legends make from the sale of the product described as "The perfect holiday or anniversary gift for executives"?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT SUM(T2.MSRP - T2.buyPrice) FROM productlines AS T1 INNER JOIN products AS T2 ON T1.productLine = T2.productLine WHERE T2.productVendor = 'Carousel DieCast Legends' AND T1.textDescription LIKE '%perfect holiday or anniversary gift for executives%' |
Write SQL query to solve given problem: Of the clients whose businesses are located in the city of Boston, calculate which of them has a higher average amount of payment.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T1.customerNumber FROM customers AS T1 INNER JOIN payments AS T2 ON T1.customerNumber = T2.customerNumber WHERE T1.city = 'Boston' GROUP BY T1.customerNumber ORDER BY SUM(T2.amount) / COUNT(T2.paymentDate) DESC LIMIT 1 |
Write SQL query to solve given problem: Calculate the total quantity ordered for 18th Century Vintage Horse Carriage and the average price.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT SUM(T2.quantityOrdered) , SUM(T2.quantityOrdered * T2.priceEach) / SUM(T2.quantityOrdered) FROM products AS T1 INNER JOIN orderdetails AS T2 ON T1.productCode = T2.productCode WHERE T1.productName = '18th Century Vintage Horse Carriage' |
Write SQL query to solve given problem: How many kinds of products did order No. 10252 contain?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT COUNT(t.productCode) FROM orderdetails t WHERE t.orderNumber = '10252' |
Write SQL query to solve given problem: Who is the sales representative that made the order which was sent to 25 Maiden Lane, Floor No. 4?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T2.firstName, T2.lastName FROM customers AS T1 INNER JOIN employees AS T2 ON T1.salesRepEmployeeNumber = T2.employeeNumber WHERE T1.addressLine1 = '25 Maiden Lane' AND T1.addressLine2 = 'Floor No. 4' |
Write SQL query to solve given problem: Where's Foon Yue Tseng's office located at? Give the detailed address.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T1.addressLine1, T1.addressLine2 FROM offices AS T1 INNER JOIN employees AS T2 ON T1.officeCode = T2.officeCode WHERE T2.firstName = 'Foon Yue' AND T2.lastName = 'Tseng' |
Write SQL query to solve given problem: Compared with the orders happened on 2005-04-08 and two days later, which day's order had a higher value?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT T2.orderDate FROM orderdetails AS T1 INNER JOIN orders AS T2 ON T1.orderNumber = T2.orderNumber WHERE STRFTIME('%Y-%m-%d', T2.orderDate) = '2005-04-08' OR STRFTIME('%Y-%m-%d', T2.orderDate) = '2005-04-10' ORDER BY T1.quantityOrdered * T1.priceEach DESC LIMIT 1 |
Write SQL query to solve given problem: How many products with the highest expected profits were sold in total?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT SUM(t2.quantityOrdered) FROM orderdetails AS t2 INNER JOIN ( SELECT t1.productCode FROM products AS t1 ORDER BY t1.MSRP - t1.buyPrice DESC LIMIT 1 ) AS t3 ON t2.productCode = t3.productCode |
Write SQL query to solve given problem: How much did Petit Auto pay on 2004-08-09?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT t1.amount FROM payments AS t1 INNER JOIN customers AS t2 ON t1.customerNumber = t2.customerNumber WHERE t2.customerName = 'Petit Auto' AND t1.paymentDate = '2004-08-09' |
Write SQL query to solve given problem: What was the contact name for the check "NR157385"?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT t2.contactFirstName, t2.contactLastName FROM payments AS t1 INNER JOIN customers AS t2 ON t1.customerNumber = t2.customerNumber WHERE t1.checkNumber = 'NR157385' |
Write SQL query to solve given problem: Which customer made the order No. 10160? Give the contact name.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT t2.contactFirstName, t2.contactLastName FROM orders AS t1 INNER JOIN customers AS t2 ON t1.customerNumber = t2.customerNumber WHERE t1.orderNumber = '10160' |
Write SQL query to solve given problem: Where was the order No. 10383 shipped to? Show me the address.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT t2.addressLine1, t2.addressLine2 FROM orders AS t1 INNER JOIN customers AS t2 ON t1.customerNumber = t2.customerNumber WHERE t1.orderNumber = '10383' |
Write SQL query to solve given problem: For the productline where the product No.S18_2949 was produced, what's the text description for that product line?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT t1.textDescription FROM productlines AS t1 INNER JOIN products AS t2 ON t1.productLine = t2.productLine WHERE t2.productCode = 'S18_2949' |
Write SQL query to solve given problem: If Dragon Souveniers, Ltd. aren't satisfied with their order and want to send a complain e-mail, which e-mail address should they send to?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT t2.email FROM customers AS t1 INNER JOIN employees AS t2 ON t1.salesRepEmployeeNumber = t2.employeeNumber WHERE t1.customerName = 'Dragon Souveniers, Ltd.' |
Write SQL query to solve given problem: How many French customers does Gerard Hernandez take care of?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT COUNT(t1.customerNumber) FROM customers AS t1 INNER JOIN employees AS t2 ON t1.salesRepEmployeeNumber = t2.employeeNumber WHERE t1.country = 'France' AND t2.firstName = 'Gerard' AND t2.lastName = 'Hernandez' |
Write SQL query to solve given problem: What was the latest order that customer No.114 made? Give the name of the product.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT t3.productName FROM orderdetails AS t1 INNER JOIN orders AS t2 ON t1.orderNumber = t2.orderNumber INNER JOIN products AS t3 ON t1.productCode = t3.productCode WHERE t2.customerNumber = '114' ORDER BY t2.orderDate DESC LIMIT 1 |
Write SQL query to solve given problem: For the product No. S18_3482 in the Order No.10108, how much discount did the customer have?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT (t1.MSRP - t2.priceEach) / t1.MSRP FROM products AS t1 INNER JOIN orderdetails AS t2 ON t1.productCode = t2.productCode WHERE t1.productCode = 'S18_3482' AND t2.orderNumber = '10108' |
Write SQL query to solve given problem: To whom does Steve Patterson report? Please give his or her full name.. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT t2.firstName, t2.lastName FROM employees AS t1 INNER JOIN employees AS t2 ON t2.employeeNumber = t1.reportsTo WHERE t1.firstName = 'Steve' AND t1.lastName = 'Patterson' |
Write SQL query to solve given problem: How do I contact the President of the company?. Keep the solution inside sql tag ```sql [SQL-Query] ``` | car_retails | SELECT t.email FROM employees t WHERE t.jobTitle = 'President' |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.