Chinastark/bird_dataset huggingface dataset:
Database: works_cycles
Note: vendor's selling price refers to standardprice;
Question: What is the highest vendor's selling price for Hex Nut 5?
SQL: SELECT productvendor.standardprice FROM productvendor INNER JOIN product ON productvendor.productid = product.productid WHERE product.name = 'Hex Nut 5' ORDER BY productvendor.standardprice DESC LIMIT 1
Database: works_cycles
Note: vendor's selling price refers to standardprice;
Question: Please list all the vendors' usual selling prices of the product Hex Nut 5.
SQL: SELECT productvendor.standardprice FROM productvendor INNER JOIN product ON productvendor.productid = product.productid WHERE product.name = 'Hex Nut 5' GROUP BY productvendor.standardprice ORDER BY count(productvendor.standardprice) DESC LIMIT 1
Database: works_cycles
Note: good credit rating refers to creditrating between 1 and 3;
Question: Among the vendors that sell the product Hex Nut 5, how many of them have a good credit rating?
SQL: SELECT count(DISTINCT vendor.name) FROM productvendor INNER JOIN product ON productvendor.productid = product.productid INNER JOIN vendor ON productvendor.businessentityid = vendor.businessentityid WHERE product.name = 'Hex Nut 5' AND vendor.creditrating = 1 AND 3
Database: works_cycles
Note: website purchasing link refers to purchasingwebserviceurl;
Question: Please list the website purchasing links of the vendors from whom the product Hex Nut 5 can be purchased.
SQL: SELECT vendor.purchasingwebserviceurl FROM productvendor INNER JOIN product ON productvendor.productid = product.productid INNER JOIN vendor ON productvendor.businessentityid = vendor.businessentityid WHERE product.name = 'Hex Nut 5'
Database: works_cycles
Note: vendor's selling price refers to standardprice; lowest selling price = MIN(standardprice);
Question: Which vendor's selling price for Hex Nut 5 is the lowest, please give the vendor's name.
SQL: SELECT vendor.name FROM productvendor INNER JOIN product ON productvendor.productid = product.productid INNER JOIN vendor ON productvendor.businessentityid = vendor.businessentityid WHERE product.name = 'Hex Nut 5' ORDER BY productvendor.standardprice LIMIT 1
Database: works_cycles
Note: preferred vendor refers to preferredvendorstatus = 1; high class refers to class = 'H';
Question: How many high-class products are sold by preferred vendors?
SQL: SELECT count(product.name) FROM productvendor INNER JOIN product USING (productid) INNER JOIN vendor ON productvendor.businessentityid = vendor.businessentityid WHERE vendor.preferredvendorstatus = 1 AND product.class = 'M'
Database: works_cycles
Note: Hex Nut 5 is name of a product;
Question: Please give all the list prices of the product LL Fork.
SQL: SELECT productlistpricehistory.listprice FROM product INNER JOIN productlistpricehistory ON product.productid = productlistpricehistory.productid WHERE product.name = 'LL Fork'
Database: works_cycles
Note: mountain product line refers to productline = 'M'; sold by over 5 vendors refers to count(name)>5;
Question: Among the products from the mountain product line, how many of them are sold by over 2 vendors?
SQL: SELECT sum(CASE WHEN product.productline = 'M' THEN 1 ELSE 0 END) FROM product INNER JOIN productvendor ON product.productid = productvendor.productid INNER JOIN vendor ON productvendor.businessentityid = vendor.businessentityid GROUP BY product.productid HAVING count(product.name) > 2
Database: works_cycles
Note: mountain product line refers to productline = 'M';
Question: Among the products that get over at least 1 review, how many of them are from the mountain product line?
SQL: SELECT sum(CASE WHEN product.productline = 'M' THEN 1 ELSE 0 END) FROM productreview INNER JOIN product ON productreview.productid = product.productid GROUP BY productreview.productid HAVING count(productreview.productreviewid) > 1
Database: works_cycles
Note: lowest rating refers to rating = 1;
Question: Please list the email adresses of the reviewers who have given the lowest rating to the product HL Mountain Pedal.
SQL: SELECT productreview.emailaddress FROM productreview INNER JOIN product ON productreview.productid = product.productid WHERE product.name = 'HL Mountain Pedal' ORDER BY productreview.rating LIMIT 1
Database: works_cycles
Note: take more than 2 days to make refers to daystomanufacture>2; out of stock refers to onorderqty = 0 or onorderqty is null;
Question: How many products that take more than 2 days to make are out of stock?
SQL: SELECT count(product.productid) FROM productvendor INNER JOIN product ON productvendor.productid = product.productid WHERE productvendor.onorderqty IS NULL OR productvendor.onorderqty = 0
Database: works_cycles
Note: take more than 2 days to make refers to daystomanufacture>2; out of stock refers to onorderqty = 0 or onorderqty is null; manufactured in house refers to makeflag = 1;
Question: Please list the products that are out of stock and purchased in house.
SQL: SELECT product.name FROM productvendor INNER JOIN product ON productvendor.productid = product.productid WHERE product.makeflag = 0 AND (productvendor.onorderqty IS NULL OR productvendor.onorderqty = 0)
Database: works_cycles
Note: salable product refers to finishedgoodsflag = 1; mountain product line refers to productline = 'M';
Question: Among the salable products from the mountain product line, how many of them have the most reviews?
SQL: SELECT sum(CASE WHEN product.productline = 'M' THEN 1 ELSE 0 END) FROM productreview INNER JOIN product ON productreview.productid = product.productid WHERE product.finishedgoodsflag = 1 GROUP BY productreview.productid ORDER BY count(productreview.productreviewid) DESC LIMIT 1
Database: works_cycles
Note: average selling price = divide(sum(standardprice), count(businessentityid));
Question: What is the average selling price of different vendors of the product Hex Nut 5?
SQL: SELECT sum(productvendor.standardprice) / count(productvendor.businessentityid) FROM productvendor INNER JOIN product ON productvendor.productid = product.productid WHERE product.name = 'Hex Nut 5'
Database: works_cycles
Note: mountain product line refers to productline = 'M'; highest average rating = max(divide(sum(rating), count(productreview)));
Question: What is the product that has the highest average rating from the mountain product line?
SQL: SELECT product.name FROM productreview INNER JOIN product ON productreview.productid = product.productid WHERE product.productline = 'M' GROUP BY product.name ORDER BY cast(sum(productreview.rating) AS REAL) / count(productreview.productid) DESC LIMIT 1
Database: works_cycles
Note: home manufactured refers to makeflag = 1; average rating = divide(sum(rating), count(productreview));
Question: Please list the top 3 house-manufactured products with the highest average rating.
SQL: SELECT product.name FROM productreview INNER JOIN product ON productreview.productid = product.productid WHERE product.makeflag = 1 GROUP BY product.name ORDER BY sum(productreview.rating) DESC LIMIT 1
Database: works_cycles
Note: non-sales employee refers to persontype = 'EM';
Question: List all the non-sales employees in ascending order of its business entitty ID.
SQL: SELECT firstname, lastname FROM person WHERE persontype = 'EM' ORDER BY businessentityid
Database: works_cycles
Note: person in the individual retail refers to persontype = 'IN';
Question: Name all person in the individual retail whose last name is 'Anderson'.
SQL: SELECT firstname, middlename, lastname FROM person WHERE lastname = 'Anderson' AND persontype = 'IN'
Database: works_cycles
Note: employee that has left the company refers to enddate is not null;
Question: List the name of employees who had left the company? When were they hired?
SQL: SELECT person.firstname, person.lastname, employee.hiredate FROM person INNER JOIN employee ON person.businessentityid = employee.businessentityid INNER JOIN employeedepartmenthistory ON employee.businessentityid = employeedepartmenthistory.businessentityid WHERE employeedepartmenthistory.enddate IS NOT NULL
Database: works_cycles
Note: salaried employee refers to salariedflag = 1; hired in 2007 and later refers to year(hiredate)>= 2007;
Question: Name all salaried employee who are hired in 2007 and later.
SQL: SELECT person.firstname, person.lastname FROM person INNER JOIN employee ON person.businessentityid = employee.businessentityid WHERE strftime('%Y', employee.hiredate) >= '2007' AND employee.salariedflag = 1
Database: works_cycles
Note: married employee refers to maritalstatus = 'M'; less than 20 vacation hours refers to vacationhours<20;
Question: List the name of married employees with less than 20 vacation hours.
SQL: SELECT person.firstname, person.lastname FROM person INNER JOIN employee ON person.businessentityid = employee.businessentityid WHERE employee.maritalstatus = 'M' AND employee.vacationhours < 20
Database: works_cycles
Note: working on night shift refers to shiftid = 3; oldest employee refers to min(birthdate); age = 2022-year(birthdate)+1;
Question: Name the oldest employee who is working on night shift. How old is the employee?
SQL: SELECT person.firstname, person.lastname , strftime('%Y', CURRENT_TIMESTAMP) - strftime('%Y', birthdate) FROM person INNER JOIN employee ON person.businessentityid = employee.businessentityid INNER JOIN employeedepartmenthistory ON employee.businessentityid = employeedepartmenthistory.businessentityid WHERE employeedepartmenthistory.shiftid = 3 ORDER BY strftime('%Y', CURRENT_TIMESTAMP) - strftime('%Y', birthdate) DESC LIMIT 1
Database: works_cycles
Note: hired in 2009 refers to year(hiredate) = 2009;
Question: List all staff in the Shipping and Receiving department who are hired in 2009.
SQL: SELECT person.firstname, person.lastname FROM person INNER JOIN employee ON person.businessentityid = employee.businessentityid INNER JOIN employeedepartmenthistory ON employee.businessentityid = employeedepartmenthistory.businessentityid INNER JOIN department ON employeedepartmenthistory.departmentid = department.departmentid WHERE strftime('%Y', employee.hiredate) = '2009' AND department.name = 'Shipping and Receiving'
Database: works_cycles
Note: oldest employee refers to min(birthdate);
Question: What is the job title of the oldest employee in the company? In which department is he in?
SQL: SELECT employee.jobtitle, department.name FROM person INNER JOIN employee ON person.businessentityid = employee.businessentityid INNER JOIN employeedepartmenthistory ON employee.businessentityid = employeedepartmenthistory.businessentityid INNER JOIN department ON employeedepartmenthistory.departmentid = department.departmentid ORDER BY employee.hiredate LIMIT 1
Database: works_cycles
Note: latest payrate refers to max(ratechangedate); average hourly payrate = divide(sum(rate), count(businessentityid)) for each departmentid;
Question: Based on the lastet payrate of each employee, calculate the average hourly payrate for each department.
SQL: SELECT avg(employeepayhistory.rate) FROM employeepayhistory INNER JOIN employeedepartmenthistory ON employeepayhistory.businessentityid = department.businessentityid INNER JOIN department ON department.departmentid = department.departmentid WHERE employeepayhistory.ratechangedate = ( SELECT max(employeepayhistory.ratechangedate) FROM employeepayhistory INNER JOIN department ON employeepayhistory.businessentityid = department.departmentid )
Database: works_cycles
Note: other than the Chief Executive Officer refers to jobtitle! = 'Chief Executive Officer'; highest payrate refers to max(rate);
Question: Other than the Chief Executive Officer, who is the employee who has the highest payrate? State the rate.
SQL: SELECT person.firstname, person.lastname FROM employeepayhistory INNER JOIN person ON employeepayhistory.businessentityid = person.businessentityid INNER JOIN employee ON person.businessentityid = employee.businessentityid WHERE employee.jobtitle NOT LIKE 'Chief Executive Officer' ORDER BY employeepayhistory.rate DESC LIMIT 1
Database: works_cycles
Question: Name the vendor who has the shortest average lead time for Product ID 319.
SQL: SELECT vendor.name FROM vendor INNER JOIN productvendor ON vendor.businessentityid = productvendor.businessentityid WHERE productvendor.productid = 319 ORDER BY productvendor.averageleadtime LIMIT 1
Database: works_cycles
Note: Australia Bike Retailer is name of vendor;
Question: List all product name from Australia Bike Retailer order by product ID.
SQL: SELECT product.name FROM vendor INNER JOIN productvendor ON vendor.businessentityid = productvendor.businessentityid INNER JOIN product ON productvendor.productid = product.productid WHERE vendor.name = 'Australia Bike Retailer'
Database: works_cycles
Note: profit on net = subtract(lastreceiptcost, standardprice); best profit on net refers to max(subtract(lastreceiptcost, standardprice));
Question: Which vendor gives the best profit on net for product ID 342?
SQL: SELECT vendor.name FROM vendor INNER JOIN productvendor ON vendor.businessentityid = productvendor.businessentityid WHERE productvendor.productid = 342 ORDER BY productvendor.lastreceiptcost - productvendor.standardprice DESC LIMIT 1
Database: works_cycles
Note: current payrate refers to max(rate); percentage increment = divide(subtract(max(rate), min(rate)), min(rate))*100%;
Question: What is the current payrate of Rob Walters? Calculate the percentage increment from his previous payrate.
SQL: SELECT employeepayhistory.rate , (max(employeepayhistory.rate) - min(employeepayhistory.rate)) * 100 / max(employeepayhistory.rate) FROM person INNER JOIN employeepayhistory ON person.businessentityid = employeepayhistory.businessentityid WHERE person.firstname = 'Rob' AND person.lastname = 'Walters'
Database: works_cycles
Note: average length of employment = AVG(subtract(2022, year(hiredate)));
Question: Calculate the average length of employment for employee working in the Research and Development deparment.
SQL: SELECT avg(strftime('%Y', CURRENT_TIMESTAMP) - strftime('%Y', employee.hiredate)) FROM employee INNER JOIN employeedepartmenthistory ON employee.businessentityid = employeedepartmenthistory.businessentityid INNER JOIN department ON employeedepartmenthistory.departmentid = department.departmentid WHERE department.name = 'Research and Development'
Database: works_cycles
Note: average age = AVG(subtract(year(now), year(hiredate)));
Question: What is the average age of employee in Adventure Works?
SQL: SELECT avg(strftime('%Y', CURRENT_TIMESTAMP) - strftime('%Y', birthdate)) FROM employee
Database: works_cycles
Note: percentage of sales representatives = divide(count(jobtitle = 'Sales Representative'), count(jobtitle))*100%;
Question: Among the employees in Adventure Works, calculate the percentage of them working as sales representatives.
SQL: SELECT cast(sum(CASE WHEN jobtitle = 'Sales Representative' THEN 1 ELSE 0 END) AS REAL) * 100 / count(businessentityid) FROM employee
Database: works_cycles
Note: Marketing Manager is a job title;
Question: Please provide contact details of all Marketing Managers. State their name and phone number.
SQL: SELECT person.firstname, person.lastname, personphone.phonenumber FROM person INNER JOIN personphone ON person.businessentityid = personphone.businessentityid INNER JOIN employee ON person.businessentityid = employee.businessentityid WHERE employee.jobtitle = 'Marketing Manager'
Database: works_cycles
Note: distinguish credt card refers to cardtype = 'Distinguish';
Question: List the person who owns a distinguish credt card.
SQL: SELECT person.firstname, person.lastname FROM creditcard INNER JOIN personcreditcard ON creditcard.creditcardid = personcreditcard.creditcardid INNER JOIN person ON personcreditcard.businessentityid = person.businessentityid WHERE creditcard.cardtype = 'Distinguish'
Database: works_cycles
Question: Name the sales person for store Area Bike Accessories. Which territory is he / she in?
SQL: SELECT salesterritory.name FROM store INNER JOIN salesperson ON store.salespersonid = salesperson.businessentityid INNER JOIN person ON salesperson.businessentityid = person.businessentityid INNER JOIN salesterritory ON salesperson.territoryid = salesterritory.territoryid WHERE store.name = 'Area Bike Accessories'
Database: works_cycles
Note: France territory refers to salesterritory.name = 'France';
Question: Name all stores and its sales representative in France territory.
SQL: SELECT store.name, person.firstname, person.lastname FROM salesterritory INNER JOIN customer ON salesterritory.territoryid = customer.territoryid INNER JOIN store ON customer.storeid = store.businessentityid INNER JOIN person ON customer.personid = person.businessentityid WHERE salesterritory.name = 'France'
Database: works_cycles
Note: Started selling in 2013 refers to year(sellstartdate) = 2013;
Question: Name all products that started selling in 2013. State its respective vendor's name.
SQL: SELECT product.name, vendor.name FROM product INNER JOIN productvendor ON product.productid = productvendor.productid INNER JOIN vendor ON productvendor.businessentityid = vendor.businessentityid WHERE strftime('%Y', product.sellstartdate) = '2013'
Database: works_cycles
Note: Highest year to date sales refers to Max(salesytd);
Question: Names the Sales Representative with the highest year to date sales.
SQL: SELECT person.firstname, person.middlename, person.lastname FROM salesperson INNER JOIN person ON salesperson.businessentityid = person.businessentityid ORDER BY salesperson.salesytd DESC LIMIT 1
Database: works_cycles
Note: MOQ refers to minimum order quantity; MOQ of 1 refers to minorderqty = 1; standard cost more than 48 refers to standardcost > 48;
Question: List all product only MOQ of 1,000 and with standard cost more than 17.
SQL: SELECT product.name FROM productvendor INNER JOIN product ON productvendor.productid = product.productid INNER JOIN vendor ON productvendor.businessentityid = vendor.businessentityid WHERE productvendor.maxorderqty = 1000 AND product.standardcost > 17
Database: works_cycles
Note: Male refers to gender = 'M'; married refers to maritalstatus = 'M'; oldest refers to Min(birthdate);
Question: Who is the oldest married male? State his job title.
SQL: SELECT person.firstname, person.lastname, employee.jobtitle FROM employee INNER JOIN person ON employee.businessentityid = person.businessentityid WHERE employee.gender = 'M' AND employee.maritalstatus = 'M' ORDER BY employee.birthdate LIMIT 1
Database: works_cycles
Question: State the vendor for product number WB-H098.
SQL: SELECT vendor.name FROM product INNER JOIN productvendor ON product.productid = productvendor.productid INNER JOIN vendor ON productvendor.businessentityid = vendor.businessentityid WHERE product.productnumber = 'WB-H098'
Database: works_cycles
Question: Find the vendor with the least average lead time for Product ID 348.
SQL: SELECT vendor.name FROM productvendor INNER JOIN vendor ON productvendor.businessentityid = vendor.businessentityid WHERE productvendor.productid = 348 ORDER BY productvendor.averageleadtime ASC LIMIT 1
Database: works_cycles
Note: born in or after 1970 refers to year(birthdate) >= 1970;
Question: State the employee who are born in or after 1970 and with the least sick leave hour.
SQL: SELECT person.firstname, person.lastname FROM employee INNER JOIN person ON employee.businessentityid = person.businessentityid WHERE strftime('%Y', employee.birthdate) > '1970' ORDER BY employee.sickleavehours LIMIT 1
Database: works_cycles
Note: Average = Divide(Sum(Substract(year(@today),year(birthdate))),Count(businessentityid) by each department ID; youngest employee refers to Min(birthdate);
Question: Calculate the average age of employee in each department and state which department has the youngest employees.
SQL: SELECT strftime('%Y', CURRENT_TIMESTAMP) - strftime('%Y', employee.birthdate) + 1 , department.name FROM employee INNER JOIN employeedepartmenthistory USING (businessentityid) INNER JOIN department USING (departmentid) ORDER BY employee.birthdate DESC LIMIT 1
Database: works_cycles
Question: Please provide the IDs of any three AdventureWorks product subcategories.
SQL: SELECT DISTINCT productcategoryid FROM productsubcategory LIMIT 3
Database: works_cycles
Note: 288th sales person refers to businessentityid = 288; predited annual sales refers to salesquota; actual sales refers to salesytd; difference = Substract(salesquota(businessentityid(288))), (salesytd(businessentityid(288)));
Question: What are the differences between the 288th salesperson's predicted annual sales and his or her actual sales thus far?
SQL: SELECT salesytd - salesquota FROM salesperson WHERE businessentityid = 288
Database: works_cycles
Note: lowest total sales in last year refers to Min(saleslastyear);
Question: Please list three businesses with the lowest total sales from last year.
SQL: SELECT businessentityid FROM salesperson ORDER BY saleslastyear LIMIT 3
Database: works_cycles
Note: revenue refers to salesytd; the most revenue refers to Max(salesytd);
Question: Which three sales regions have generated the most revenue thus far?
SQL: SELECT territoryid FROM salesterritory ORDER BY salesytd DESC LIMIT 3
Database: works_cycles
Note: resellers refers to category = 'Reseller';
Question: What categories of offers qualify for group discounts for resellers?
SQL: SELECT TYPE FROM specialoffer WHERE category = 'Reseller'
Database: works_cycles
Note: excess inventory refers to type = 'Excess Inventory'; highest possible discount refers to Max(discountpct);
Question: What is the highest possible discount rate for 'Excess Inventory'?
SQL: SELECT discountpct FROM specialoffer WHERE TYPE = 'Excess Inventory' ORDER BY discountpct DESC LIMIT 1
Database: works_cycles
Note: product number 818 refers to productid = 818; estimated manufacturing cost refers plannedcost; actual manufacturing cost refers to actualcost; difference = Substract(plannedcost(productid(818))),(actualcost(productid(818)));
Question: What is the difference between the actual manufacturing cost of product number 818 and the estimated manufacturing cost?
SQL: SELECT plannedcost - actualcost FROM workorderrouting WHERE productid = 818
Database: works_cycles
Note: still need to be assembled means the assembly doesn't finish or still going on which refers to enddate IS NULL; a depth of 2 refers to bomlevel = 2;
Question: How many materials still need to be assembled and have a depth of 2 between each component and their parent product?
SQL: SELECT count(*) FROM billofmaterials WHERE bomlevel = 2 AND enddate IS NULL
Database: works_cycles
Note: approved refers to status = 2; confidential document refers to documentsummary is null;
Question: How many of the approved documents are confidential?
SQL: SELECT count(documentnode) FROM document WHERE status = 2 AND documentsummary IS NULL
Database: works_cycles
Note: multiple types of tax refers to name like '%+%';
Question: What are the sales tax records charged by multiple types of tax?
SQL: SELECT salestaxrateid FROM salestaxrate WHERE name LIKE '%+%'
Database: works_cycles
Note: work order transaction refers to transactiontype = 'W';
Question: Which work order transaction number has the highest product quantity?
SQL: SELECT transactionid FROM transactionhistory WHERE transactiontype = 'W' ORDER BY quantity DESC LIMIT 1
Database: works_cycles
Note: not recommended refers to preferredvendorstatus = 0;
Question: Please list any 3 vendors that are not recommended by Adventure Works.
SQL: SELECT name FROM vendor WHERE preferredvendorstatus = 0 LIMIT 3
Database: works_cycles
Note: not preferable refers to preferredvendorstatus = 0; still work refers to activeflag = 1;
Question: How many vendors does Adventure Works still work with but are not preferable?
SQL: SELECT count(businessentityid) FROM vendor WHERE preferredvendorstatus = 0 AND activeflag = 1
Database: works_cycles
Note: began work in 2009 or later refers to startdate>= 2009;
Question: How many employees who began working in 2009 or later had night shifts?
SQL: SELECT count(employeedepartmenthistory.businessentityid) FROM employeedepartmenthistory INNER JOIN shift ON employeedepartmenthistory.shiftid = shift.shiftid WHERE shift.shiftid = 3 AND strftime('%Y', shift.starttime) >= '2009'