Chinastark/bird_dataset huggingface dataset:
Database: regional_sales
Note: "Apollo Ltd" and "Pacific Ltd" are both customer names; total number of orders refers to COUNT(ordernumber);
Question: Compare the total number of orders between customer "Apollo Ltd" and "Pacific Ltd".
SQL: SELECT sum(CASE WHEN customers.`customer names` = 'Apollo Ltd' THEN 1 ELSE 0 END), sum(CASE WHEN customers.`customer names` = 'Pacific Ltd' THEN 1 ELSE 0 END) FROM `sales orders` INNER JOIN customers ON customers.customerid = sales orders._customerid
Database: regional_sales
Note: "Aurora" refers to city name = 'Aurora (Township)'; "Babylon" refers to city name = 'Babylong (Town)'; more order refers to Max(Count(ordernumber));
Question: Find the store ID with more orders between "Aurora" and "Babylon" city.
SQL: SELECT store locations.storeid FROM `sales orders` INNER JOIN `store locations` ON store locations.storeid = sales orders._storeid WHERE store locations.`city name` = 'Aurora (Township)' OR store locations.`city name` = 'Babylon (Town)' GROUP BY store locations.storeid ORDER BY count(sales orders.ordernumber) DESC LIMIT 1
Database: regional_sales
Note: "Anthony Torres" is the name of sales team; distributor channel refers to sales channel = 'Distributor';
Question: List down the customer names and product names of the order made by "Anthony Torres" via distributor channel.
SQL: SELECT DISTINCT customers.`customer names`, products.`product name` FROM customers INNER JOIN `sales orders` ON sales orders._customerid = customers.customerid INNER JOIN `sales team` ON sales team.salesteamid = sales orders._salesteamid INNER JOIN products ON products.productid = sales orders._productid WHERE sales team.`sales team` = 'Anthony Torres' AND sales orders.`sales channel` = 'Distributor'
Database: regional_sales
Note: IDs refers to customerid; total net profit of above 5000 USD refers to SUM(Subtract(unit price, unit cost)) > 5000;
Question: Mention the customer names and IDs which ordered total net profit of above 5000 USD through online channel.
SQL: SELECT DISTINCT `customer names`, customerid FROM ( SELECT customers.`customer names`, customers.customerid , sum(replace(sales orders.`unit price`, ',', '') - replace(sales orders.`unit cost`, ',', '')) AS t FROM `sales orders` sales orders INNER JOIN customers customers ON customers.customerid = sales orders._customerid WHERE sales orders.`sales channel` = 'Online' GROUP BY customers.customerid ) WHERE t > 5000
Database: regional_sales
Note: floral product refers to product name = 'Floral'; total net profit = SUM(Subtract(unit price, unit cost)); delivered in 2021 refers to deliverydate LIKE '%/21';
Question: Find the net profit of the floral products which were delivered in 2021.
SQL: SELECT sum(replace(sales orders.`unit price`, ',', '') - replace(sales orders.`unit cost`, ',', '')) FROM `sales orders` INNER JOIN products ON products.productid = sales orders._productid WHERE sales orders.deliverydate LIKE '%/%/21' AND products.`product name` = 'Floral'
Database: regional_sales
Note: number of order refers to ordernumber; population of 3000000 to 4000000 refers to population BETWEEN 3000000 AND 4000000;
Question: Count the number of orders made from the store in city with population of 3000000 to 4000000.
SQL: SELECT count(sales orders.ordernumber) FROM `sales orders` INNER JOIN `store locations` ON store locations.storeid = sales orders._storeid WHERE store locations.population BETWEEN 3000000 AND 4000000
Database: regional_sales
Note: products refers to product name; via wholesale channel refers to sales channel = 'Wholesale';
Question: Name the products via wholesale channel of the store under Pacific/Honolulu time zone.
SQL: SELECT t FROM ( SELECT DISTINCT CASE  WHEN store locations.`time zone` = 'Pacific/Honolulu' AND sales orders.`sales channel` = 'Wholesale' THEN products.`product name` ELSE NULL END AS t FROM products products INNER JOIN `sales orders` sales orders ON sales orders._productid = products.productid INNER JOIN `store locations` store locations ON store locations.storeid = sales orders._storeid ) WHERE t IS NOT NULL
Database: regional_sales
Note: ordered on 6th June 2018 refers to orderdate = '6/5/18';
Question: List the order numbers and product names which were ordered on 6th June, 2018.
SQL: SELECT DISTINCT ordernumber, `product name` FROM ( SELECT iif(sales orders.orderdate = '6/6/18', sales orders.ordernumber, NULL) AS "OrderNumber" , iif(sales orders.orderdate = '6/6/18', products.`product name`, NULL) AS "Product Name" FROM products products INNER JOIN `sales orders` sales orders ON sales orders._productid = products.productid ) WHERE ordernumber IS NOT NULL AND `product name` IS NOT NULL
Database: regional_sales
Note: "Weimei Corp" is the customer names; in 2018, 2019 and 2020 refers to SUBSTR (orderdate, -2) IN ('18', '19', '20') : Average order = Divide (Count (ordernumber), 3);
Question: Find the average yearly order by customer Weimei Corp for 2018, 2019 and 2020.
SQL: SELECT count(sales orders.ordernumber) / 3 FROM `sales orders` INNER JOIN customers ON customers.customerid = sales orders._customerid WHERE (sales orders.orderdate LIKE '%/%/18' AND customers.`customer names` = 'Weimei Corp') OR (sales orders.orderdate LIKE '%/%/19' AND customers.`customer names` = 'Weimei Corp') OR (sales orders.orderdate LIKE '%/%/20' AND customers.`customer names` = 'Weimei Corp')
Database: regional_sales
Note: "WARE-NMK1003" is the warehousecode; in 2019 refers to SUBSTR(orderdate, -2) = '19'; average = Divide (Count (ordernumber where SUBSTR(orderdate, -2) = '19'), 12); Percentage = Divide (Count(ordernumber where warehousecode = 'WARE-NMK1003'), Count(ordernumber)) * 100; 'Floor Lamps' is the product name; number of orders refers to Count(ordernumber);
Question: Calculate the average monthly order and percentage of warehouse "WARE-NMK1003" in 2019. Among them, mention number of orders for floor lamps.
SQL: SELECT cast(sum(CASE WHEN sales orders.warehousecode = 'WARE-NMK1003' THEN 1 ELSE 0 END) AS REAL) / 12 , cast(sum(CASE WHEN sales orders.warehousecode = 'WARE-NMK1003' THEN 1 ELSE 0 END) AS REAL) * 100 / count(sales orders.ordernumber), count(CASE WHEN products.`product name` = 'Floor Lamps' AND sales orders.warehousecode = 'WARE-NMK1003' THEN sales orders.`order quantity` ELSE NULL END) FROM products INNER JOIN `sales orders` ON sales orders._productid = products.productid WHERE sales orders.orderdate LIKE '%/%/19'
Database: regional_sales
Note: ID is 11 refers to _customerid = 11;
Question: Indicate the procured dates for the customer whose ID is 11.
SQL: SELECT DISTINCT t FROM ( SELECT iif(_customerid = 11, procureddate, NULL) AS t FROM `sales orders` ) WHERE t IS NOT NULL
Database: regional_sales
Note: "Distributor" is the sales channel; minimum quantity refers to Min(order quantity);
Question: How many orders through distributor were for the minimum quantity?
SQL: SELECT sum(CASE WHEN `order quantity` = 1 AND `sales channel` = 'Distributor' THEN 1 ELSE 0 END) FROM `sales orders`
Database: regional_sales
Note: ID refers to _salesteamid; 10% discount refers to discount applied = 0.1; 'In-Store' is the sales channel;
Question: List by ID all sales teams that have sold products at a 10% discount in store.
SQL: SELECT DISTINCT t FROM ( SELECT CASE  WHEN `discount applied` = '0.1' AND `sales channel` = 'In-Store' THEN _salesteamid ELSE NULL END AS t FROM `sales orders` ) WHERE t IS NOT NULL
Database: regional_sales
Note: "Brooklyn" is the CityName; population of less than 3 million refers to population < 3000000;
Question: How many Borough-type stores located in the city of Brooklyn have a population of less than 3 million?
SQL: SELECT sum(CASE WHEN population < 3000000 AND TYPE = 'Borough' AND `city name` = 'Brooklyn' THEN 1 ELSE 0 END) FROM `store locations`
Database: regional_sales
Question: How many states are in the Midwest region?
SQL: SELECT count(DISTINCT t) FROM ( SELECT CASE  WHEN region = 'Midwest' THEN state ELSE NULL END AS t FROM regions ) WHERE t IS NOT NULL
Database: regional_sales
Note: products refers to product name; highest net profit = Max(Subtract(unit price, unit cost));
Question: What are the top 10 products with the highest net profit?
SQL: SELECT products.`product name` FROM `sales orders` INNER JOIN products ON products.productid = sales orders._productid GROUP BY sales orders._productid ORDER BY sum(replace(sales orders.`unit price`, ',', '') - replace(sales orders.`unit cost`, ',', '')) DESC LIMIT 10
Database: regional_sales
Note: name of customer refers to customer names; order of 3 unit refers to order quantity = 3; in February 2018 refers to orderdate LIKE '2/%/18';
Question: Indicate the name of the customers who have placed an order of 3 units in February 2018.
SQL: SELECT t FROM ( SELECT DISTINCT CASE  WHEN sales orders.`order quantity` = 3 AND sales orders.orderdate LIKE '2/%/18' THEN customers.`customer names` END AS t FROM customers customers INNER JOIN `sales orders` sales orders ON sales orders._customerid = customers.customerid ) WHERE t IS NOT NULL
Database: regional_sales
Note: name of sales team refers to sales team; 'Apotheca, Ltd' is the customer names;
Question: What are the names of the sales teams that have served to customer Apotheca, Ltd?
SQL: SELECT DISTINCT sales team.`sales team` FROM customers INNER JOIN `sales orders` ON sales orders._customerid = customers.customerid INNER JOIN `sales team` ON sales team.salesteamid = sales orders._salesteamid WHERE customers.`customer names` = 'Apotheca, Ltd'
Database: regional_sales
Note: "WARE-UHY1004" is the warehousecode;
Question: In which regions are the stores that have shipped products through the WARE-UHY1004 warehouse?
SQL: SELECT t FROM ( SELECT DISTINCT CASE  WHEN sales orders.warehousecode = 'WARE-UHY1004' THEN regions.region END AS t FROM regions regions INNER JOIN `store locations` store locations ON store locations.statecode = regions.statecode INNER JOIN `sales orders` sales orders ON sales orders._storeid = store locations.storeid ) WHERE t IS NOT NULL
Database: regional_sales
Note: "Shawn Torres" is the name of sales team; Audio product refers to product name = 'Audio';
Question: List all the cities where Shawn Torres sells Audio products.
SQL: SELECT t FROM ( SELECT DISTINCT CASE  WHEN products.`product name` = 'Audio' AND sales team.`sales team` = 'Shawn Torres' THEN store locations.`city name` ELSE NULL END AS t FROM `store locations` store locations INNER JOIN `sales orders` sales orders ON sales orders._storeid = store locations.storeid INNER JOIN `sales team` sales team ON sales team.salesteamid = sales orders._salesteamid INNER JOIN products products ON products.productid = sales orders._productid ) WHERE t IS NOT NULL
Database: regional_sales
Note: ordered on 10/21/18 refers to orderdate = '10/21/18'; delivered on 11/21/19 refers to deliverydate = '11/21/19'; name of product refers to product name;
Question: Lists the name of the product and customer who placed an order on 10/21/18 and it was delivered on 11/21/19.
SQL: SELECT products.`product name`, customers.`customer names` FROM customers INNER JOIN `sales orders` ON sales orders._customerid = customers.customerid INNER JOIN products ON products.productid = sales orders._productid WHERE sales orders.orderdate = '10/21/18' AND sales orders.deliverydate = '11/21/19'
Database: regional_sales
Note: October 27, 2018 refers to procureddate = '10/27/18'; 'Oregon' is the state;
Question: How many stores procured products on October 27, 2018, in the city of Oregon?
SQL: SELECT sum(CASE WHEN sales orders.procureddate = '10/27/18' AND store locations.`city name` = 'Orlando' THEN 1 ELSE 0 END) FROM `sales orders` INNER JOIN `store locations` ON store locations.storeid = sales orders._storeid
Database: regional_sales
Note: highest median income refers to Max(median income);
Question: What sales channels are used the most in the 3 places with the highest median income?
SQL: SELECT `sales channel` FROM ( SELECT sales orders.`sales channel` FROM `sales orders` INNER JOIN `store locations` ON store locations.storeid = sales orders._storeid ORDER BY store locations.`median income` DESC LIMIT 3 ) GROUP BY `sales channel` ORDER BY count(`sales channel`) DESC LIMIT 1
Database: regional_sales
Note: highest net profit = Max(Subtract (unit price, unit cost));
Question: List the 5 sales teams that have made sales with the highest net profits.
SQL: SELECT sales team.`sales team` FROM `sales orders` INNER JOIN `sales team` ON sales team.salesteamid = sales orders._salesteamid ORDER BY replace(sales orders.`unit price`, ',', '') - replace(sales orders.`unit cost`, ',', '') DESC LIMIT 5
Database: regional_sales
Note: highest discount applied refers to Max(discount applied);
Question: What is the highest discount applied by the store located in a city of the state of Colorado whose land area is 111039036.
SQL: SELECT max(sales orders.`discount applied`) FROM `sales orders` INNER JOIN `store locations` ON store locations.storeid = sales orders._storeid WHERE store locations.state = 'Colorado' AND store locations.`land area` = 111039036
Database: regional_sales
Question: How many different time zones are there in the Northeast region?
SQL: SELECT count(DISTINCT store locations.`time zone`) FROM regions INNER JOIN `store locations` ON store locations.statecode = regions.statecode WHERE regions.region = 'Northeast'
Database: regional_sales
Note: in the South refers to region = 'South'; type of store that is most popular refers to Max(Count(type));
Question: What type of store is most popular in the South?
SQL: SELECT DISTINCT CASE WHEN max(store locations.population) THEN store locations.type END FROM regions INNER JOIN `store locations` ON store locations.statecode = regions.statecode
Database: regional_sales
Note: "WARE-MKL1006" is the warehousecode; most shipment to region refers to Max(Count(region));
Question: To which region does the sales team that has used the WARE-MKL1006 warehouse the most times for its shipments belong?
SQL: SELECT sales team.region FROM `sales orders` INNER JOIN `sales team` ON sales team.salesteamid = sales orders._salesteamid WHERE sales orders.warehousecode = 'WARE-MKL1006' GROUP BY sales team.region ORDER BY count(sales orders.ordernumber) DESC LIMIT 1
Database: regional_sales
Note: highest sales order unit price refers to Max(unit price);
Question: In which city is the store with the highest sales order unit price located?
SQL: SELECT store locations.`city name` FROM `sales orders` INNER JOIN `store locations` ON store locations.storeid = sales orders._storeid WHERE replace(sales orders.`unit price`, ',', '') = ( SELECT replace(sales orders.`unit price`, ',', '') FROM `sales orders` INNER JOIN `store locations` ON store locations.storeid = sales orders._storeid ORDER BY replace(sales orders.`unit price`, ',', '') DESC LIMIT 1 ) ORDER BY replace(sales orders.`unit price`, ',', '') DESC LIMIT 1
Database: regional_sales
Note: "Ole Group" is the customer names; online purchase refers to sales channel = 'Online'; made in May 2019 refers to orderdate LIKE '5/%/19';
Question: How many online purchases did Ole Group make in May 2019?
SQL: SELECT sum(CASE WHEN sales orders.`sales channel` = 'Online' AND customers.`customer names` = 'Ole Group' AND sales orders.orderdate LIKE '5/%/19' THEN 1 ELSE 0 END) FROM `sales orders` INNER JOIN customers ON customers.customerid = sales orders._customerid
Database: regional_sales
Note: less need for products refers to order quantity = 1; purchased through a distributor refers to sales channel = 'Distributor'; 'Harri county' is the county;
Question: How many stores with less need for products, and purchased through a distributor, are located in Washtenaw County?
SQL: SELECT sum(CASE WHEN sales orders.`order quantity` = 1 AND sales orders.`sales channel` = 'Distributor' AND store locations.county = 'Washtenaw County' THEN 1 ELSE 0 END) FROM `sales orders` INNER JOIN `store locations` ON store locations.storeid = sales orders._storeid
Database: regional_sales
Note: least purchased product refers to Min(Count(product name)); 'Santa Clarita' is the City;
Question: What is the least purchased product by stores in the city of Santa Clarita?
SQL: SELECT products.`product name` FROM products INNER JOIN `sales orders` ON sales orders._productid = products.productid INNER JOIN `store locations` ON store locations.storeid = sales orders._storeid WHERE store locations.`city name` = 'Santa Clarita' GROUP BY products.`product name` ORDER BY count(products.`product name`) ASC LIMIT 1
Database: regional_sales
Note: WARE-PUJ1005 is the warehousecode; fewest times refers to Min (Count(warehousecode));
Question: At what Latitude and Longitude is the store that has used the WARE-PUJ1005 warehouse the fewest times?
SQL: SELECT store locations.latitude, store locations.longitude FROM `sales orders` INNER JOIN `store locations` ON store locations.storeid = sales orders._storeid WHERE sales orders.warehousecode = 'WARE-PUJ1005' GROUP BY store locations.storeid ORDER BY count(sales orders.warehousecode) ASC LIMIT 1
Database: regional_sales
Note: sales order on 04/04/2020 refers to orderdate = '4/4/20'; 'New York' is  the city name; percentage = Divide (Sum(ordernumber where city name = 'New York'), Count (ordernumber)) * 100;
Question: What percentage of sell orders on 04/04/2020 were for the state of New York?
SQL: SELECT cast(sum(CASE WHEN store locations.state = 'New York' THEN 1 ELSE 0 END) AS REAL) * 100 / count(sales orders.ordernumber) FROM `sales orders` INNER JOIN `store locations` ON store locations.storeid = sales orders._storeid WHERE sales orders.orderdate = '4/4/20'
Database: regional_sales
Note: average land area = Divide (Sum(land area), Count(land area));
Question: What is the average land area of ​​the cities in which stores that purchased products for a unit price of 998.30 are located?
SQL: SELECT avg(store locations.`land area`) FROM `sales orders` INNER JOIN `store locations` ON store locations.storeid = sales orders._storeid WHERE sales orders.`unit price` = '998.30'
Database: regional_sales
Note: "New Hampshire" is the state; average household income = AVG(household income);
Question: What is the average household income in cities in the state of New Hampshire where there are stores of the type city?
SQL: SELECT avg(store locations.`household income`) FROM regions INNER JOIN `store locations` ON store locations.statecode = regions.statecode WHERE store locations.state = 'New Hampshire' AND store locations.type = 'City'
Database: regional_sales
Note: "Midwest" is the region;
Question: How many sales teams are there in the Midwest?
SQL: SELECT sum(CASE WHEN region = 'Midwest' THEN 1 ELSE 0 END) FROM `sales team`
Database: regional_sales
Note: order date after 1/1/2018 refers to orderdate > '1/1/2018';
Question: Indicate order numbers with an order date after 1/1/2018.
SQL: SELECT DISTINCT t FROM ( SELECT CASE  WHEN orderdate > '1/1/18' THEN ordernumber ELSE NULL END AS t FROM `sales orders` ) WHERE t IS NOT NULL
Database: regional_sales
Note: "Midwest" is the region;
Question: How many sales channels does the sales team have in the Midwest?
SQL: SELECT count(sales orders.`sales channel`) FROM `sales orders` INNER JOIN `sales team` ON sales team.salesteamid = sales orders._salesteamid WHERE sales team.region = 'Midwest'
Database: regional_sales
Note: highest unit price refers to Max(unit price);
Question: Which sales team has the other with the highest unit price?
SQL: SELECT sales team.`sales team` FROM `sales orders` INNER JOIN `sales team` ON sales team.salesteamid = sales orders._salesteamid WHERE replace(sales orders.`unit price`, ',', '') = ( SELECT replace(sales orders.`unit price`, ',', '') FROM `sales orders` INNER JOIN `sales team` ON sales team.salesteamid = sales orders._salesteamid ORDER BY replace(sales orders.`unit price`, ',', '') DESC LIMIT 1 ) ORDER BY replace(sales orders.`unit price`, ',', '') DESC LIMIT 1
Database: regional_sales
Note: most discount refers to Max(discount applied);
Question: Which regions have online sales channels that have the most discounts?
SQL: SELECT sales team.region FROM `sales orders` INNER JOIN `sales team` ON sales team.salesteamid = sales orders._salesteamid WHERE sales orders.`sales channel` = 'Online' ORDER BY sales orders.`discount applied` DESC LIMIT 1
Database: regional_sales
Note: "Apollo Ltd" is the customer names; most expensive unit price refers to max(unit price);
Question: Which Apollo Ltd customer's order number has the most expensive unit price, indicating the order date?
SQL: SELECT sales orders.ordernumber, sales orders.orderdate FROM `sales orders` INNER JOIN customers ON customers.customerid = sales orders._customerid WHERE customers.`customer names` = 'Apollo Ltd' ORDER BY sales orders.`unit price` DESC LIMIT 1
Database: regional_sales
Note: "Elorac, Corp" is the customer names;
Question: Provide order number, warehouse code of customers Elorac, Corp.
SQL: SELECT DISTINCT sales orders.ordernumber, sales orders.warehousecode FROM `sales orders` INNER JOIN customers ON customers.customerid = sales orders._customerid WHERE customers.`customer names` = 'Elorac, Corp'
Database: regional_sales
Note: "Cocktail Glasses" is the product name; customer refers to customer names;
Question: Name of customers who have ordered Cocktail Glasses by online sales channel.
SQL: SELECT t FROM ( SELECT DISTINCT CASE  WHEN products.`product name` = 'Cocktail Glasses' AND sales orders.`sales channel` = 'Online' THEN customers.`customer names` END AS t FROM customers customers INNER JOIN `sales orders` sales orders ON sales orders._customerid = customers.customerid INNER JOIN products products ON products.productid = sales orders._productid ) WHERE t IS NOT NULL
Database: regional_sales
Note: "Arizona" is the name of state; most net profit = Max(Subtract( unit price, unit cost));
Question: Which store in Arizona has the most net profit?
SQL: SELECT store locations.storeid FROM `sales orders` INNER JOIN `store locations` ON store locations.storeid = sales orders._storeid WHERE store locations.state = 'Arizona' ORDER BY sales orders.`unit price` - sales orders.`unit cost` DESC LIMIT 1
Database: regional_sales
Note: "Florida" and "Texas" are both the name of state; Computer product refers to product name = 'Computers; difference in unit price = Subtract (unit price where state = 'Florida', unit price where state = 'Texas');
Question: How much more is the Florida store's computer product unit price than the Texas store?
SQL: SELECT sum(CASE WHEN store locations.state = 'Florida' THEN sales orders.`unit price` ELSE 0 END) - sum(CASE WHEN store locations.state = 'Texas' THEN sales orders.`unit price` ELSE 0 END) FROM products INNER JOIN `sales orders` ON sales orders._productid = products.productid INNER JOIN `store locations` ON store locations.storeid = sales orders._storeid WHERE products.`product name` = 'Computers'
Database: regional_sales
Note: order quantity greater than 5 refers to order quantity > 5;
Question: Among sales teams in Midwest region, which sales team has an order quantity greater than 5?
SQL: SELECT DISTINCT sales team.`sales team` FROM `sales orders` INNER JOIN `sales team` ON sales team.salesteamid = sales orders._salesteamid WHERE sales team.region = 'Midwest' AND sales orders.`order quantity` > 5
Database: regional_sales
Note: "California" is the name of state; in store refers to sales channel = 'In-Store'; 20% discount refers to discount applied = '0.2';
Question: Please indicate store id in the state of California that have been applied 20% discount in store.
SQL: SELECT t FROM ( SELECT DISTINCT CASE  WHEN store locations.state = 'California' AND sales orders.`sales channel` = 'In-Store' AND sales orders.`discount applied` = 0.2 THEN store locations.storeid END AS t FROM `sales orders` sales orders INNER JOIN `store locations` store locations ON store locations.storeid = sales orders._storeid ) WHERE t IS NOT NULL