db_id
stringclasses 69
values | question
stringlengths 24
325
| evidence
stringlengths 0
673
| SQL
stringlengths 23
804
| question_id
int64 0
9.43k
| difficulty
stringclasses 1
value |
---|---|---|---|---|---|
works_cycles
|
For all the products, list the product name and its corresponding start date for the current standard cost.
|
The current standard cost refers to EndDate is NULL
|
SELECT T1.Name, T2.StartDate FROM Product AS T1 INNER JOIN ProductCostHistory AS T2 ON T1.ProductID = T2.ProductID WHERE T2.EndDate IS NULL
| 7,000 | |
works_cycles
|
List the products whereby the standard cost is $80 more than previous standard cost in history.
|
SUBTRACT(product.StandardCost, CostHistory.StandardCost)>80
|
SELECT T1.Name FROM Product AS T1 INNER JOIN ProductCostHistory AS T2 ON T1.ProductID = T2.ProductID WHERE T1.StandardCost - T2.StandardCost > 80 GROUP BY T1.Name
| 7,001 | |
works_cycles
|
Name all products and total quantity for each item for shopping cart ID 14951.
|
SELECT T1.Name, T2.Quantity FROM Product AS T1 INNER JOIN ShoppingCartItem AS T2 ON T1.ProductID = T2.ProductID WHERE T2.ShoppingCartID = 14951
| 7,002 | ||
works_cycles
|
List the product name with more than 5 quantity in the shopping cart.
|
Product with more than 5 quantity refers to Quantity>5
|
SELECT T1.Name FROM Product AS T1 INNER JOIN ShoppingCartItem AS T2 ON T1.ProductID = T2.ProductID WHERE T2.Quantity > 5
| 7,003 | |
works_cycles
|
For all the purchase order transactions, name all the products with low quality.
|
Low quality refers to the product's quality class, therefore Class = 'L'
|
SELECT DISTINCT T1.Name FROM Product AS T1 INNER JOIN TransactionHistory AS T2 ON T1.ProductID = T2.ProductID WHERE T1.Class = 'L' AND T2.TransactionType = 'P' ORDER BY T1.Name
| 7,004 | |
works_cycles
|
Provide all the transactions whereby the quantiy is more than 10,000 pieces. State the product name and the selling price.
|
Quantity more than 10,000 pieces refers to Quantity>10000; selling price refers to ListPrice
|
SELECT DISTINCT T1.Name, T1.ListPrice FROM Product AS T1 INNER JOIN TransactionHistory AS T2 ON T1.ProductID = T2.ProductID WHERE T2.Quantity > 10000
| 7,005 | |
works_cycles
|
Which is a high quality product but with the lowest transacted quantity?
|
High quality refers to the product's quality class, therefore Class = 'H'; the lowest transacted quantity refers to Quantity = 1
|
SELECT T1.Name FROM Product AS T1 INNER JOIN TransactionHistory AS T2 ON T1.ProductID = T2.ProductID WHERE T1.Class = 'H' ORDER BY T2.Quantity ASC LIMIT 1
| 7,006 | |
works_cycles
|
How many transactions are there for product under the Mountain line?
|
The Mountain line refers to the product line, therefore ProductLine = 'M'
|
SELECT COUNT(T2.TransactionID) FROM Product AS T1 INNER JOIN TransactionHistory AS T2 ON T1.ProductID = T2.ProductID WHERE T1.ProductLine = 'M'
| 7,007 | |
works_cycles
|
How much would be the total sales profit for shopping cart ID 20621 ?
|
Sales profit = MULTIPLY(SUBTRACT(ListPrice, StandardCost; Quantity)), where ShoppingCartID = '20621'
|
SELECT SUM((T1.ListPrice - T1.StandardCost) * T2.Quantity) FROM Product AS T1 INNER JOIN ShoppingCartItem AS T2 ON T1.ProductID = T2.ProductID WHERE T2.ShoppingCartID = 20621
| 7,008 | |
works_cycles
|
List all product names that are high in quality. Please also state its selling price.
|
High quality refers to the product's quality class, therefore Class = 'H'
|
SELECT Name, ListPrice FROM Product WHERE Class = 'H'
| 7,009 | |
works_cycles
|
Which product line has the most products that are salable?
|
Saleable product refers to FinishedGoodsFlag = 1
|
SELECT ProductLine FROM Product WHERE FinishedGoodsFlag = 1 GROUP BY ProductLine ORDER BY COUNT(FinishedGoodsFlag) DESC LIMIT 1
| 7,010 | |
works_cycles
|
Provide details of review from reviewer whose name begin with letter 'J'. State the product ID, rating and comments.
|
reviewer whose name begin with letter 'J' = ReviewerName LIKE 'J%'
|
SELECT ProductID, Rating, Comments FROM ProductReview WHERE ReviewerName LIKE 'J%'
| 7,011 | |
works_cycles
|
State the product name, product line, rating and the selling price of product with the lowest rating.
|
Product with the lowest rating refers to the rating
given by the
reviewer where Rating = 1
|
SELECT T1.Name, T1.ProductLine, T2.Rating, T1.ListPrice FROM Product AS T1 INNER JOIN ProductReview AS T2 ON T1.ProductID = T2.ProductID ORDER BY T2.Rating ASC LIMIT 1
| 7,012 | |
works_cycles
|
Calculate the profit of each products. List all products with more than $100 in profit.
|
Profit = AVG(SUBTRACT(ListPrice, StandardCost)>100
|
SELECT DISTINCT Name FROM Product WHERE ListPrice - StandardCost > 100
| 7,013 | |
works_cycles
|
List down the product name, reviewer name, rating and comments for product under the road line.
|
The Road line refers to the product line, therefore ProductLine = 'R'
|
SELECT T1.Name, T2.ReviewerName, T2.Rating, T2.Comments FROM Product AS T1 INNER JOIN ProductReview AS T2 USING (productID) WHERE T1.ProductLine = 'R'
| 7,014 | |
works_cycles
|
How many people reviewed for product named HL Mountain Pedal? What is the average rating?
|
AVG(Rating) = DIVIDE(SUM(rating), COUNT(ReviewerName))
|
SELECT COUNT(T1.ProductID), AVG(T2.Rating) FROM Product AS T1 INNER JOIN ProductReview AS T2 ON T1.ProductID = T2.ProductID WHERE T1.Name = 'HL Mountain Pedal'
| 7,015 | |
works_cycles
|
List the purchase order whereby all received quantity were rejected? Name those product.
|
Rejected refers rejected product in which to RejectedQty = 1
|
SELECT T1.Name FROM Product AS T1 INNER JOIN PurchaseOrderDetail AS T2 ON T1.ProductID = T2.ProductID WHERE T2.RejectedQty = T2.ReceivedQty AND T2.RejectedQty <> 0
| 7,016 | |
works_cycles
|
Among all products without any rejected quantity, which product has the highest line total? State the product name and unit price.
|
Product without any rejected quantity refers to RejectedQty = 0
|
SELECT T1.Name, T2.UnitPrice FROM Product AS T1 INNER JOIN PurchaseOrderDetail AS T2 ON T1.ProductID = T2.ProductID WHERE T2.RejectedQty = 0 ORDER BY T2.LineTotal DESC LIMIT 1
| 7,017 | |
works_cycles
|
List all product names and its product line for all purchase order with order quantity of 5000 or more.
|
Purchase order with order quantity of 5000 or more refers to OrderQty> = 5000
|
SELECT T1.Name, T1.ProductLine FROM Product AS T1 INNER JOIN PurchaseOrderDetail AS T2 ON T1.ProductID = T2.ProductID WHERE T2.OrderQty > 4999
| 7,018 | |
works_cycles
|
What is the total ordered quantity for products under the 'Touring' line?
|
The Touring line refers to the product line, therefore ProductLine = 'T'
|
SELECT SUM(T2.OrderQty) FROM Product AS T1 INNER JOIN PurchaseOrderDetail AS T2 ON T1.ProductID = T2.ProductID WHERE T1.ProductLine = 'T'
| 7,019 | |
works_cycles
|
Among the low quality product, which product has the highest line total? List the product name and its line total?
|
Low quality refers to the product's quality class, therefore Class = 'L'
|
SELECT T1.Name, T2.LineTotal FROM Product AS T1 INNER JOIN PurchaseOrderDetail AS T2 ON T1.ProductID = T2.ProductID WHERE Class = 'L' ORDER BY OrderQty * UnitPrice DESC LIMIT 1
| 7,020 | |
works_cycles
|
Which product has the highest profit on net? State the product name.
|
Profit on net = SUBTRACT(LastReceiptCost, StandardPrice)
|
SELECT T1.Name FROM Product AS T1 INNER JOIN ProductVendor AS T2 ON T1.ProductID = T2.ProductID ORDER BY T2.LastReceiptCost - T2.StandardPrice DESC LIMIT 1
| 7,021 | |
works_cycles
|
List all products with minimum order quantity of 100 and order them by product name in descending order.
|
miinimum order quantity refers to MinOrderQty = 100
|
SELECT DISTINCT T1.Name FROM Product AS T1 INNER JOIN ProductVendor AS T2 ON T1.ProductID = T2.ProductID WHERE T2.MinOrderQty = 100 ORDER BY T1.Name DESC
| 7,022 | |
works_cycles
|
List the name and calculate its profit for product with the highest rating in review.
|
Profit = SUBTRACT(ListPrice, StandardCost); the highest rating in review refers to Rating = 5
|
SELECT T1.Name, T1.ListPrice - T1.StandardCost FROM Product AS T1 INNER JOIN ProductReview AS T2 ON T1.ProductID = T2.ProductID ORDER BY T2.Rating DESC LIMIT 1
| 7,023 | |
works_cycles
|
What is the total profit all transactions with product ID 827?
|
Profit = MULTIPLY(SUBTRACT(ListPrice, StandardCost) Quantity))
|
SELECT SUM((T1.ListPrice - T1.StandardCost) * T2.Quantity) FROM Product AS T1 INNER JOIN TransactionHistory AS T2 ON T1.ProductID = T2.ProductID WHERE T1.ProductID = 827
| 7,024 | |
works_cycles
|
Which currency pair's average exchange rate for the day is the highest?
|
currency pair refers to FromCurrencyCode/ToCurrencyCode
|
SELECT FromCurrencyCode, ToCurrencyCode FROM CurrencyRate ORDER BY AverageRate DESC LIMIT 1
| 7,025 | |
works_cycles
|
How many products with the highest unit price were ordered?
|
number of products refers to OrderQty
|
SELECT OrderQty FROM PurchaseOrderDetail ORDER BY UnitPrice DESC LIMIT 1
| 7,026 | |
works_cycles
|
Between Northwest and Southeast of the United States, which territory one recorded the highest amount of sales last year?
|
United States refers to CountryRegionCode = 'US';
|
SELECT Name FROM SalesTerritory WHERE CountryRegionCode = 'US' AND (Name = 'Northwest' OR Name = 'Southeast') ORDER BY SalesLastYear DESC LIMIT 1
| 7,027 | |
works_cycles
|
What is the full name of the Document Control Manager who is in charge of all Level 1 approved documents?
|
full Name = FirstName+MiddleName+Last Name; approved document refers to Status = 2;
|
SELECT T1.FirstName, T1.MiddleName, T1.LastName FROM Person AS T1 INNER JOIN Employee AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID INNER JOIN Document AS T3 ON T3.Owner = T2.BusinessEntityID WHERE T2.JobTitle = 'Document Control Manager' AND T3.DocumentLevel = 1 AND T3.Status = 2 GROUP BY T1.FirstName, T1.MiddleName, T1.LastName
| 7,028 | |
works_cycles
|
Which customer has the highest subtotal amount of sales orders whose assigned to the salesperson with the highest bonus?
|
highest subtotal amount of sales order refers to max(SubTotal);
|
SELECT T1.CustomerID FROM SalesOrderHeader AS T1 INNER JOIN SalesPerson AS T2 ON T1.SalesPersonID = T2.BusinessEntityID ORDER BY T1.SubTotal DESC LIMIT 1
| 7,029 | |
works_cycles
|
What is the total price of Sales Order ID 46625 with Volume Discount 11 to 14 and Product ID 716?
|
total price = multiply(UnitPrice, OrderQty);
|
SELECT T2.UnitPrice * T2.OrderQty FROM SpecialOffer AS T1 INNER JOIN SalesOrderDetail AS T2 ON T1.SpecialOfferID = T2.SpecialOfferID WHERE T1.Description = 'Volume Discount 11 to 14' AND T1.SpecialOfferID = 2 AND T2.ProductID = 716 AND T2.SalesOrderID = 46625
| 7,030 | |
works_cycles
|
Of the products that has a reorder inventory point of no more than 600, how many manufactured in-house products that takes 1 day to manufacture with BOM Level 4 are there?
|
ReorderPoint<600; product is manufactured in-house refers to Makeflag = 1;
|
SELECT COUNT(T1.ProductID) FROM Product AS T1 INNER JOIN BillOfMaterials AS T2 ON T1.ProductID = T2.ProductAssemblyID WHERE T1.MakeFlag = 1 AND T1.DaysToManufacture = 1 AND T2.BOMLevel = 4 AND T1.ReorderPoint <= 600
| 7,031 | |
works_cycles
|
What is the highest amount of bonus earned by the sales person in Canada?
|
Canada is name of a sales territory
|
SELECT T2.Bonus FROM SalesTerritory AS T1 INNER JOIN SalesPerson AS T2 ON T1.TerritoryID = T2.TerritoryID WHERE T1.CountryRegionCode = 'CA' ORDER BY T2.SalesQuota DESC LIMIT 1
| 7,032 | |
works_cycles
|
What are the names of the product that has the lowest rating?
|
lowest rating refers to Rating = 1;
|
SELECT T2.Name FROM ProductReview AS T1 INNER JOIN Product AS T2 ON T1.ProductID = T2.ProductID WHERE T1.Rating = ( SELECT Rating FROM ProductReview ORDER BY Rating ASC LIMIT 1 )
| 7,033 | |
works_cycles
|
How many of the workers who started working in 2009 are from the Production Department?
|
StartDate BETWEEN '2009-01-01' AND '2009-12-31';
|
SELECT COUNT(T2.BusinessEntityID) FROM Department AS T1 INNER JOIN EmployeeDepartmentHistory AS T2 ON T1.DepartmentID = T2.DepartmentID WHERE T2.StartDate >= '2009-01-01' AND T2.StartDate < '2010-01-01' AND T1.Name = 'Production'
| 7,034 | |
works_cycles
|
Who is the company's highest-paid single female employee? Include her full name and job title.
|
full name = FirstName+MiddleName+LastName; highest-paid refers to max(Rate); single refers to Status = 'S'; female refers to Gender = 'F';
|
SELECT T3.FirstName, T3.MiddleName, T3.LastName, T1.JobTitle FROM Employee AS T1 INNER JOIN EmployeePayHistory AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID INNER JOIN Person AS T3 ON T2.BusinessEntityID = T3.BusinessEntityID WHERE T1.MaritalStatus = 'S' AND T1.Gender = 'F' ORDER BY T2.Rate DESC LIMIT 1
| 7,035 | |
works_cycles
|
Who is the Vice President of Engineering and when did he join the company? Indicate his/her full name.
|
full name = FirstName+MiddleName+LastName; HiredDate refers to the date the person joins the company;
|
SELECT T2.FirstName, T2.MiddleName, T2.LastName, T1.HireDate FROM Employee AS T1 INNER JOIN Person AS T2 USING (BusinessEntityID) WHERE T1.JobTitle = 'Vice President of Engineering'
| 7,036 | |
works_cycles
|
How many active employees whose payrate is equal or below 30 per hour.
|
active employee refers to CurrentFlag = 1; Rate< = 30;
|
SELECT COUNT(T1.BusinessEntityID) FROM Employee AS T1 INNER JOIN EmployeePayHistory AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T1.CurrentFlag = 1 AND T2.Rate <= 30
| 7,037 | |
works_cycles
|
Which department has a worker who just recently started working?
|
recently started working refers to latest StartDate;
|
SELECT T1.Name FROM Department AS T1 INNER JOIN EmployeeDepartmentHistory AS T2 ON T1.DepartmentID = T2.DepartmentID ORDER BY T2.StartDate DESC LIMIT 1
| 7,038 | |
works_cycles
|
Which store sales person was reently hired? Indicate his/her full name and gender.
|
SC is an abbreviation for Store Contact; store contact person refers to PersonType = 'SC'; recently hired refers to latest StartDate;
|
SELECT T2.FirstName, T2.MiddleName, T2.LastName, T1.Gender FROM Employee AS T1 INNER JOIN Person AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T2.PersonType = 'SP'
| 7,039 | |
works_cycles
|
How frequently do the employee with the least number of sick leave hours get paid?
|
least number of sick leave refers to min(SickLeaveHours); PayFrequency = 1 means ‘Salary received monthly’; PayFrequency = 2 means ‘Salary received biweekly';
|
SELECT T2.PayFrequency FROM Employee AS T1 INNER JOIN EmployeePayHistory AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID ORDER BY T1.SickLeaveHours ASC LIMIT 1
| 7,040 | |
works_cycles
|
Which job title has the lowest pay?
|
lowest pay refers to min(Rate);
|
SELECT T1.JobTitle FROM Employee AS T1 INNER JOIN EmployeePayHistory AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID ORDER BY T2.Rate ASC LIMIT 1
| 7,041 | |
works_cycles
|
What is the total number of employees that worked in the Finance department?
|
SELECT COUNT(T2.BusinessEntityID) FROM Department AS T1 INNER JOIN EmployeeDepartmentHistory AS T2 USING (DepartmentID) WHERE T1.Name = 'Finance'
| 7,042 | ||
works_cycles
|
What is the profit of the product with the highest list price and of the product with the lowest list price other than 0? Indicates the depth the component is from its parent.
|
profit = subtract(ListPrice, StandardCost); the depth the component from its parent refers to BOMLevel;
|
SELECT ( SELECT ListPrice - StandardCost FROM Product WHERE ListPrice != 0 ORDER BY ListPrice DESC LIMIT 1 ) , ( SELECT ListPrice - StandardCost FROM Product WHERE ListPrice != 0 ORDER BY ListPrice LIMIT 1 )
| 7,043 | |
works_cycles
|
Among the companies to which Adventure Works Cycles purchases parts or other goods, what is the profit on net obtained from the vendor who has an above average credit rating? Kindly indicate each names of the vendor and the corresponding net profits.
|
above average credit rating refers to CreditRating = 3; profit on net = subtract(LastReceiptCost, StandardPrice);
|
SELECT T2.Name, T1.LastReceiptCost - T1.StandardPrice FROM ProductVendor AS T1 INNER JOIN Vendor AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T2.CreditRating = 3
| 7,044 | |
works_cycles
|
How many accounts have an address that is too long?
|
address that is too long refers to AddressLine2! = null
|
SELECT COUNT(*) FROM Address WHERE AddressLine2 <> ''
| 7,045 | |
works_cycles
|
What is the postal code of the street address of the account that is latest updated?
|
account latest updated refers to year(ModifiedDate) = 2022 and month(ModifiedDate) = 10
|
SELECT PostalCode FROM Address ORDER BY ModifiedDate DESC LIMIT 1
| 7,046 | |
works_cycles
|
What is the longest assembly item duration for bicycles?
|
longest assembly item duration = max(subtract(EndDate,StartDate))
|
SELECT JULIANDAY(EndDate) - JULIANDAY(StartDate) FROM BillOfMaterials ORDER BY JULIANDAY(EndDate) - JULIANDAY(StartDate) DESC LIMIT 1
| 7,047 | |
works_cycles
|
How many assembly items for bicycles aren't finished?
|
assembly lines that are not finished refers to EndDate = null
|
SELECT COUNT(BillOfMaterialsID) FROM BillOfMaterials WHERE EndDate IS NULL
| 7,048 | |
works_cycles
|
Please list the unit measure code of the component that is of the greatest need in quantity to create the assembly.
|
greatest need in quantity refers to max(PerAssemblyQty)
|
SELECT UnitMeasureCode FROM BillOfMaterials ORDER BY PerAssemblyQty DESC LIMIT 1
| 7,049 | |
works_cycles
|
How many product maintenance documents are private?
|
product maintenance documents are private refers to DocumentSummary = null
|
SELECT COUNT(DocumentNode) FROM Document WHERE DocumentSummary IS NULL
| 7,050 | |
works_cycles
|
Please list the titles of the documents that are pending approval.
|
documents pending approval refers to Status = 1
|
SELECT Title FROM Document WHERE Status = 1
| 7,051 | |
works_cycles
|
Please list the job titles of the employees who has a document that has been approved.
|
document has been approved refers to Status = 2
|
SELECT DISTINCT T2.BusinessEntityID, T2.JobTitle FROM Document AS T1 INNER JOIN Employee AS T2 ON T1.Owner = T2.BusinessEntityID WHERE T1.Status = 2
| 7,052 | |
works_cycles
|
What is the pay frequency of the oldest employee?
|
oldest employee refers to min(BirthDate); PayFrequency = 1 refers to ‘Salary received monthly’; PayFrequency = 2 refers to ‘Salary received biweekly'
|
SELECT T1.PayFrequency FROM EmployeePayHistory AS T1 INNER JOIN Employee AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID ORDER BY T2.BirthDate ASC LIMIT 1
| 7,053 | |
works_cycles
|
Among the employees whose pay frequencies are the highest, how many of them are married?
|
married refers to MaritalStatus = M; highest pay frequency refers to PayFrequency = 2
|
SELECT COUNT(T1.BusinessEntityID) FROM EmployeePayHistory AS T1 INNER JOIN Employee AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T2.MaritalStatus = 'M' AND T1.PayFrequency = ( SELECT PayFrequency FROM EmployeePayHistory ORDER BY PayFrequency DESC LIMIT 1 )
| 7,054 | |
works_cycles
|
For the employee who has been hired the latest, what is his or her pay rate?
|
hired the latest refers to max(HireDate)
|
SELECT T1.Rate FROM EmployeePayHistory AS T1 INNER JOIN Employee AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID ORDER BY T2.HireDate DESC LIMIT 1
| 7,055 | |
works_cycles
|
Among the employees who have a pay rate of above 40, how many of them are male?
|
pay rate above 40 refers to Rate>40; male employee refers to Gender = M
|
SELECT SUM(CASE WHEN T2.Gender = 'M' THEN 1 ELSE 0 END) FROM EmployeePayHistory AS T1 INNER JOIN Employee AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T1.Rate > 40
| 7,056 | |
works_cycles
|
What is the highest pay rate of the employees who are exempt from collective bargaining?
|
employee exempt from collective bargaining refers to SalariedFlag = 1; highest pay rate refers to max(Rate)
|
SELECT T1.Rate FROM EmployeePayHistory AS T1 INNER JOIN Employee AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T2.SalariedFlag = 1 ORDER BY T1.Rate DESC LIMIT 1
| 7,057 | |
works_cycles
|
For the employees who have the highest pay frequency, please list their vacation hours.
|
highest pay frequency refers to PayFrequency = 2
|
SELECT T2.VacationHours FROM EmployeePayHistory AS T1 INNER JOIN Employee AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T2.BusinessEntityID = ( SELECT BusinessEntityID FROM EmployeePayHistory ORDER BY Rate DESC LIMIT 1 )
| 7,058 | |
works_cycles
|
What is the pay rate of the employee who has the longest vacation hours?
|
longest vacation hour refers to max(VacationHours)
|
SELECT T1.Rate FROM EmployeePayHistory AS T1 INNER JOIN Employee AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID ORDER BY T2.VacationHours DESC LIMIT 1
| 7,059 | |
works_cycles
|
How many employees with a pay rate of over 35 have more than 10 sick leave hours?
|
more than 10 sick leave hours refers to SickLeaveHours>10; pay rate over 35 refers to Rate>35;
|
SELECT COUNT(T1.BusinessEntityID) FROM EmployeePayHistory AS T1 INNER JOIN Employee AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T2.SickLeaveHours > 10 AND T1.Rate > 35
| 7,060 | |
works_cycles
|
Among the active male employees, how many of them are paid with the highest frequency?
|
active status of employees refers to CurrentFlag = 1; Male refers to Gender = 'M'; highest frequency refers to PayFrequency = 2;
|
SELECT COUNT(T1.BusinessEntityID) FROM EmployeePayHistory AS T1 INNER JOIN Employee AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T2.CurrentFlag = 1 AND T2.Gender = 'M' AND T1.PayFrequency = 2
| 7,061 | |
works_cycles
|
How many male employees have the job position of sales person?
|
Sales person refers to PersonType = 'SP'; Male refers to Gender = 'M';
|
SELECT COUNT(T1.BusinessEntityID) FROM Employee AS T1 INNER JOIN Person AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T1.Gender = 'M' AND T2.PersonType = 'SP'
| 7,062 | |
works_cycles
|
What is the job position of the oldest employee?
|
Oldest employee refers to Max ( Subtract((now())-BirthDate));
|
SELECT T2.PersonType FROM Employee AS T1 INNER JOIN Person AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID ORDER BY T1.BirthDate ASC LIMIT 1
| 7,063 | |
works_cycles
|
What is the name style of the employee with the lowest pay rate?
|
lowest pay rate refers to Min(Rate);
|
SELECT T2.NameStyle FROM EmployeePayHistory AS T1 INNER JOIN Person AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T1.Rate IS NOT NULL ORDER BY T1.Rate ASC LIMIT 1
| 7,064 | |
works_cycles
|
Among the employees who are married, how many of them have a western name style?
|
married refers to MaritalStatus = 'M'; western name style refers to NameStyle = '0';
|
SELECT COUNT(T1.BusinessEntityID) FROM Employee AS T1 INNER JOIN Person AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T2.NameStyle = 0 AND T1.MaritalStatus = 'M'
| 7,065 | |
works_cycles
|
Among the employees who have more than 10 hours of sick leave, how many of them wish to receive e-mail promotions?
|
Contact does wish to receive e-mail promotions refers to EmailPromotion = (1,2); more than 10 hours of sick leave refer to SickLeaveHours >10;
|
SELECT COUNT(T1.BusinessEntityID) FROM Employee AS T1 INNER JOIN Person AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T2.EmailPromotion = 1 AND T1.SickLeaveHours > 10
| 7,066 | |
works_cycles
|
Please list the employees who have more than 20 vacations hours and wish to receive e-mail promotions.
|
Contact does wish to receive e-mail promotions refers to EmailPromotion = (1,2); more than 20 vacations hours refers to VacationHours>20
|
SELECT T1.BusinessEntityID FROM Employee AS T1 INNER JOIN Person AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T2.EmailPromotion = 1 AND T1.VacationHours > 20
| 7,067 | |
works_cycles
|
Please give the additional contact information of the oldest employee with the jod position of sales person.
|
Sales person refers to PersonType = 'SP'; oldest employee refers to Max (Subtract((now())-BirthDate));
|
SELECT T2.AdditionalContactInfo FROM Employee AS T1 INNER JOIN Person AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE PersonType = 'SP' ORDER BY T1.BirthDate ASC LIMIT 1
| 7,068 | |
works_cycles
|
What is the first name of the male employee who has a western name style?
|
western name style refers to NameStyle = 0; Male refers to Gender = 'M';
|
SELECT T2.FirstName FROM Employee AS T1 INNER JOIN Person AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T2.NameStyle = 0 AND T1.Gender = 'M'
| 7,069 | |
works_cycles
|
Among the active employees, how many of them have a courtesy title of "Mr"?
|
active status of employees refers to CurrentFlag = 1;
|
SELECT COUNT(T1.BusinessEntityID) FROM Employee AS T1 INNER JOIN Person AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T1.CurrentFlag = 1 AND T2.Title = 'Mr.'
| 7,070 | |
works_cycles
|
Please give the personal information of the married employee who has the highest pay rate.
|
married refers to MaritalStatus = 'M'; Highest pay rate refers to Max(Rate)
|
SELECT T2.Demographics FROM Employee AS T1 INNER JOIN Person AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID INNER JOIN EmployeePayHistory AS T3 ON T2.BusinessEntityID = T3.BusinessEntityID WHERE T1.MaritalStatus = 'M' ORDER BY T3.Rate DESC LIMIT 1
| 7,071 | |
works_cycles
|
What is the surname suffix of the employee who works as a store contact and has the longest sick leave hours?
|
store contact refers to PersonType = 'SC';
|
SELECT T2.Suffix FROM Employee AS T1 INNER JOIN Person AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T2.PersonType = 'SP' ORDER BY T1.SickLeaveHours DESC LIMIT 1
| 7,072 | |
works_cycles
|
Among the married employees with the highest pay frequency, how many of them have an eastern name style?
|
married refers to MaritalStatus = 'M'; Eastern name style refers to NameStyle = 1;
|
SELECT COUNT(T1.BusinessEntityID) FROM Employee AS T1 INNER JOIN Person AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID INNER JOIN EmployeePayHistory AS T3 ON T2.BusinessEntityID = T3.BusinessEntityID WHERE T1.MaritalStatus = 'M' AND T2.NameStyle = 1 AND T3.Rate = ( SELECT Rate FROM EmployeePayHistory ORDER BY Rate DESC LIMIT 1 )
| 7,073 | |
works_cycles
|
How many active employees do not wish to receive e-mail promotions?
|
active status of employees refers to CurrentFlag = 1; the employee does not wish to receive an e-mail promotion refers to EmailPromotion = 0;
|
SELECT COUNT(T1.BusinessEntityID) FROM Employee AS T1 INNER JOIN Person AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T1.CurrentFlag = 1 AND T2.EmailPromotion = 1
| 7,074 | |
works_cycles
|
Please list the credit card IDs of the employees who work as store contact.
|
store contact refers to PersonType = 'SC';
|
SELECT T2.CreditCardID FROM Person AS T1 INNER JOIN PersonCreditCard AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T1.PersonType = 'SC'
| 7,075 | |
works_cycles
|
How many vacation hours do the male employees have on average?
|
employee refers to PersonType = 'EM'; Male refers to Gender = 'M'; Average = Divide( SUM(VacationHours(PersonType = 'EM'& Gender = 'M')),Count(BusinessEntityID(PersonType = 'EM' & Gender = 'M')));
|
SELECT CAST(SUM(T1.VacationHours) AS REAL) / COUNT(T1.BusinessEntityID) FROM Employee AS T1 INNER JOIN Person AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T1.Gender = 'M' AND T2.PersonType = 'EM'
| 7,076 | |
works_cycles
|
Among the employees who are married and wish to receive e-mail promotions, how much higher is their highest pay rate from the average pay rate?
|
married refers to MaritalStatus = 'M'; Contact does wish to receive e-mail promotions from Adventure Works refers to EmailPromotion = 1; Average = Divide (Sum(Rate (MaritalStatus = 'M' & EmailPromotion = 1))), Count (BusinessEntityID (MaritalStatus = 'M' & EmailPromotion = 1)); MAX(Rate (MaritalStatus = 'M' & EmailPromotion = 1) - Average;
|
SELECT MAX(T1.Rate) - SUM(T1.Rate) / COUNT(T1.BusinessEntityID) FROM EmployeePayHistory AS T1 INNER JOIN Person AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID INNER JOIN Employee AS T3 ON T2.BusinessEntityID = T3.BusinessEntityID WHERE T2.EmailPromotion = 2 AND T3.MaritalStatus = 'M'
| 7,077 | |
works_cycles
|
If a married employee has a western name style, what is the probability of him or her working as a store contact?
|
married refers to MaritalStatus = 'M'; western name style refers to NameStyle = 0; store contact refers to PersonType = 'SC'; probability = Divide (Count (BusinessEntityID( PersonType = 'SC' & MaritalStatus = 'M')), Count (BusinessEntityID ( PersonType) & MariatlStatus = 'M'))
|
SELECT CAST(COUNT(IIF(T1.PersonType = 'SC', T1.PersonType, NULL)) AS REAL) / COUNT(T1.PersonType) FROM Person AS T1 INNER JOIN Employee AS T2 WHERE T1.PersonType = 'SC' AND T1.NameStyle = 0 AND T2.MaritalStatus = 'M'
| 7,078 | |
works_cycles
|
Among the active employees with over 10 hours of sick leave, what is the percentage of the employees with over 20 vacation hours?
|
CurrentFlag = 1 refers to the active status of employees; Percentage = Divide (Count (BusinessEntityID (CurrentFlag = 1 & VacationHours >20 & SickLeaveHours > 10)), Count (BusinessEntityID (CurrentFlag = 1 & SickLeaveHours>10))) * 100;
|
SELECT CAST(SUM(CASE WHEN T2.VacationHours > 20 THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(T1.BusinessEntityID) FROM EmployeePayHistory AS T1 INNER JOIN Employee AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T2.CurrentFlag = 1 AND T2.SickLeaveHours > 10
| 7,079 | |
works_cycles
|
Average of the last receipt cost of the products whose average lead time is 60 days.
|
average = DIVIDE(SUM(lastreceiptcost), COUNT(OnorderQty)) where AverageLeadTime = 60
|
SELECT SUM(LastReceiptCost) / COUNT(ProductID) FROM ProductVendor WHERE AverageLeadTime = 60
| 7,080 | |
works_cycles
|
Average cost of purchase orders made during the first six months of 2012.
|
purchase orders refers to TransactionType = 'P'; first six months of 2012 refers to TransactionDate bewteen '2012-01-01'and '2012-06-30'; average = DIVIDE(ActualCost where TransactionType = 'P', count(TransactionID))
|
SELECT CAST(SUM(ActualCost) AS REAL) / COUNT(TransactionID) FROM TransactionHistoryArchive WHERE TransactionType = 'P' AND TransactionDate >= '2012-01-01' AND TransactionDate < '2012-07-01'
| 7,081 | |
works_cycles
|
What percentage of male employees hired throughout the years 2009 are married?
|
male refers to Gender = 'M'; hired throughout the years 2009 refers to Year(HireDate) = 2009; married refers to MaritalStatus = 'M'; percentage = DIVIDE(count(BusinessEntityID(Gender = 'M'& Year(HireDate) = '2009& MaritalStatus = 'M')), count(BusinessEntityID(Gender = 'M'& Year(HireDate) = 2009)))
|
SELECT CAST(SUM(CASE WHEN MaritalStatus = 'M' THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(BusinessEntityID) FROM Employee WHERE SUBSTR(HireDate, 1, 4) = '2009' AND Gender = 'M'
| 7,082 | |
works_cycles
|
What percentage of people named Mary who wants Receive Email promotions of AdventureWorks and selected partners are store contacts?
|
wants Receive Email promotions of AdventureWorks and selected partners refers to EmailPromotion = 2; store contact refers to PersonType = 'SC'; percentage = DIVIDE(count(BusinessEntityID(FirstName = 'Marry'&EmailPromotion = '2')),count(BusinessEntityID)))
|
SELECT CAST(SUM(CASE WHEN EmailPromotion = 2 THEN 1 ELSE 0 END) AS REAL) * 100 / SUM(CASE WHEN PersonType = 'SC' THEN 1 ELSE 0 END) FROM Person WHERE FirstName = 'Mary'
| 7,083 | |
works_cycles
|
List, by ProductID, all products whose profit, relative to the standard price, is negative.
|
Profit = SUBTRACT(StandardPrice, LastRecipeCost)
|
SELECT DISTINCT ProductID FROM ProductVendor WHERE StandardPrice - LastReceiptCost < 0
| 7,084 | |
works_cycles
|
What is the average total due price of products with approved status?
|
approved refers to Status = 2 , average total due price = AVG( DIVIDE(TotalDue, SUM(Status = 2 )))
|
SELECT SUM(TotalDue) / COUNT(TotalDue) FROM PurchaseOrderHeader WHERE Status = 2
| 7,085 | |
works_cycles
|
What is the percentage, by number of sales order units, for orders with quantities not greater than 3 and a discount of 0.2?
|
quantities not greater than 3 refers to OrderQty<3; discount of 0.2 refers to UnitPriceDiscount = 0.2; percentage = DIVIDE(count(SalesOrderID(OrderQty<3 & UnitPriceDiscount = 0.2)), count(SalesOrderID))*100%
|
SELECT CAST(SUM(CASE WHEN OrderQty < 3 AND UnitPriceDiscount = 0.2 THEN 1 ELSE 0 END) AS REAL) / COUNT(SalesOrderID) FROM SalesOrderDetail
| 7,086 | |
works_cycles
|
Lists all companies by BusinessEntityID that increased their current year sales by more than 60% over last year's sales and have a bonus greater than 3,000.
|
increased their current year sales by more than 60% refers to
DIVIDE(SUBTRACT(SalesYTD, SalesLastYear),SalesLastYear)>0.6
|
SELECT BusinessEntityID FROM SalesPerson WHERE SalesYTD > SalesLastYear + SalesLastyear * 0.6 AND Bonus > 3000
| 7,087 | |
works_cycles
|
Add the number of businesses that indicate their home address as their address and those whose address corresponds to the shipping address.
|
their home address as their address refers to AddressTypeID = 2; address corresponds to the shipping address refers to AddressTypeID = 5
|
SELECT SUM(CASE WHEN T2.Name = 'Home' THEN 1 ELSE 0 END) , SUM(CASE WHEN T2.Name = 'Shipping' THEN 1 ELSE 0 END) FROM BusinessEntityAddress AS T1 INNER JOIN AddressType AS T2 ON T1.AddressTypeID = T2.AddressTypeID
| 7,088 | |
works_cycles
|
Identifies the ID number of the customer whose sales order for 32 units had a unit price of 35.
|
sales order for 32 units refers to OrderQty = 32
|
SELECT T2.CustomerID FROM SalesOrderDetail AS T1 INNER JOIN Customer AS T2 WHERE T1.UnitPrice = 35 AND T1.OrderQty = 32
| 7,089 | |
works_cycles
|
What company has a Colonial Voice card that expired in March 2005?
|
Colonial Voice card refers to CardType = 'ColonialVoice' ; expired in March 2005 refers to ExpMonth = 3, ExpYear = 2005
|
SELECT T2.BusinessEntityID FROM CreditCard AS T1 INNER JOIN PersonCreditCard AS T2 ON T1.CreditCardID = T2.CreditCardID WHERE T1.CardType = 'ColonialVoice' AND T1.ExpMonth = 3 AND T1.ExpYear = 2005
| 7,090 | |
works_cycles
|
What is the credit rating of the company whose average lead time is 16 days for a standard price of 18.9900 and whose last receipt date is August 27, 2011?
|
last receipt date is August 17, 2011 refers to LastReceiptDate> = '2011-08-17 00:00:00' and LastReceiptDate < '2011-08-18 00:00:00';
|
SELECT T2.CreditRating FROM ProductVendor AS T1 INNER JOIN Vendor AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T1.StandardPrice = 18.9900 AND T1.AverageLeadTime = 16 AND STRFTIME('%Y-%m-%d', T1.LastReceiptDate) = '2011-08-27'
| 7,091 | |
works_cycles
|
Calculate the number of products if we add the products of the accessories and components categories.
|
SELECT COUNT(ProductID) FROM Product WHERE Name LIKE '%accessories %' OR Name LIKE '%components%'
| 7,092 | ||
works_cycles
|
What is the job title of the newest employee in department 12?
|
newest employee refers to MAX(StartDate)
|
SELECT T1.JobTitle FROM Employee AS T1 INNER JOIN EmployeeDepartmentHistory AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T2.DepartmentID = 12 ORDER BY T2.StartDate DESC LIMIT 1
| 7,093 | |
works_cycles
|
List the first and last name of all unmarried male Production Supervisors.
|
unmarried refers to MaritalStatus = 'S', male refers to Gender = 'M', Production Supervisors is a job title
|
SELECT T2.FirstName, T2.LastName FROM Employee AS T1 INNER JOIN Person AS T2 ON T1.BusinessEntityID = T2.BusinessEntityID WHERE T1.MaritalStatus = 'S' AND T1.Gender = 'M' AND T1.JobTitle LIKE 'Production Supervisor%'
| 7,094 | |
works_cycles
|
How many products are there if we add all those located in the Subassembly category?
|
located in the Subassembly category refers to Name = 'Subassembly'
|
SELECT COUNT(T1.LocationID) FROM Location AS T1 INNER JOIN ProductInventory AS T2 USING (LocationID) WHERE T1.Name = 'Subassembly'
| 7,095 | |
works_cycles
|
Sum the total number of products rejected for having a trim length that is too long.
|
number of product rejected refers to ScrapedQty; trim length that is too long refers to scrap reason where Name = 'Trim length too long'
|
SELECT SUM(T2.ScrappedQty) FROM ScrapReason AS T1 INNER JOIN WorkOrder AS T2 ON T1.ScrapReasonID = T2.ScrapReasonID WHERE T1.Name = 'Trim length too long'
| 7,096 | |
works_cycles
|
Calculate the total quantity of purchased product that has been prepared by employee number 257 and is in pending shipment status.
|
employee number 257 refers to EmployeeID = 257; pending shipment status refers to Status = 3
|
SELECT SUM(T2.OrderQty) FROM PurchaseOrderHeader AS T1 INNER JOIN PurchaseOrderDetail AS T2 ON T1.PurchaseOrderID = T2.PurchaseOrderID WHERE T1.Status = 1
| 7,097 | |
works_cycles
|
If we discount the products that do not have any type of offer, how many different products have been sold in an amount greater than 2 units per order?
|
do not have any type of offer refers to Description = 'No Discount'; sold in an amount greater than 2 refers to OrderQty>2
|
SELECT COUNT(DISTINCT T1.ProductID) FROM SalesOrderDetail AS T1 INNER JOIN SpecialOfferProduct AS T2 ON T1.SpecialOfferID = T2.SpecialOfferID INNER JOIN SpecialOffer AS T3 ON T2.SpecialOfferID = T3.SpecialOfferID WHERE T1.OrderQty > 2 AND T1.UnitPriceDiscount = 0
| 7,098 | |
works_cycles
|
What type of transaction was made with the only yellow product, size 62 and with a minimum inventory stock of 500 units?
|
yellow product refers to Color = 'Yellow'; minimum inventory stock of 500 units refers to SafetyStockLevel = 500
|
SELECT DISTINCT T2.TransactionType FROM Product AS T1 INNER JOIN TransactionHistory AS T2 ON T1.ProductID = T2.ProductID WHERE T1.Size = 62 AND T1.Color = 'Yellow' AND T1.SafetyStockLevel = 500
| 7,099 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.