1sf/bird-sql-train-with-schema huggingface dataset:
Database: regional_sales
Tables: Customers, Products, Regions, Sales Team, Store Locations, Sales Orders
Columns (table index, column name): -1, *, 0, CustomerID, 0, Customer Names, 1, ProductID, 1, Product Name, 2, StateCode, 2, State, 2, Region, 3, SalesTeamID, 3, Sales Team, 3, Region, 4, StoreID, 4, City Name, 4, County, 4, StateCode, 4, State, 4, Type, 4, Latitude, 4, Longitude, 4, AreaCode, 4, Population, 4, Household Income, 4, Median Income, 4, Land Area, 4, Water Area, 4, Time Zone, 5, OrderNumber, 5, Sales Channel, 5, WarehouseCode, 5, ProcuredDate, 5, OrderDate, 5, ShipDate, 5, DeliveryDate, 5, CurrencyCode, 5, _SalesTeamID, 5, _CustomerID, 5, _StoreID, 5, _ProductID, 5, Order Quantity, 5, Discount Applied, 5, Unit Price, 5, Unit Cost
Question: Name the sales team name who had orders with the greatest net profit in 2020.
Evidence: net profit can be computed as SUBTRACT(Unit Price, Unit Cost); the greatest net profit in 2020 refers to MAX(net profit) where OrderDate LIKE '%/20';
SQL: SELECT T2.`Sales Team` FROM `Sales Orders` AS T1 INNER JOIN `Sales Team` AS T2 ON T2.SalesTeamID = T1._SalesTeamID WHERE T1.OrderDate LIKE '%/%/20' GROUP BY T2.`Sales Team` ORDER BY SUM(REPLACE(T1.`Unit Price`, ',', '') - REPLACE(T1.`Unit Cost`, ',', '')) DESC LIMIT 1
Database: regional_sales
Tables: Customers, Products, Regions, Sales Team, Store Locations, Sales Orders
Columns (table index, column name): -1, *, 0, CustomerID, 0, Customer Names, 1, ProductID, 1, Product Name, 2, StateCode, 2, State, 2, Region, 3, SalesTeamID, 3, Sales Team, 3, Region, 4, StoreID, 4, City Name, 4, County, 4, StateCode, 4, State, 4, Type, 4, Latitude, 4, Longitude, 4, AreaCode, 4, Population, 4, Household Income, 4, Median Income, 4, Land Area, 4, Water Area, 4, Time Zone, 5, OrderNumber, 5, Sales Channel, 5, WarehouseCode, 5, ProcuredDate, 5, OrderDate, 5, ShipDate, 5, DeliveryDate, 5, CurrencyCode, 5, _SalesTeamID, 5, _CustomerID, 5, _StoreID, 5, _ProductID, 5, Order Quantity, 5, Discount Applied, 5, Unit Price, 5, Unit Cost
Question: Sate the order number and calculate the net profit for each order under Joshua Bennett.
Evidence: net profit can be computed as SUBTRACT(Unit Price, Unit Cost); Joshua Bennett is the name of Sales Team;
SQL: SELECT T1.OrderNumber , REPLACE(T1.`Unit Price`, ',', '') - REPLACE(T1.`Unit Cost`, ',', '')  FROM `Sales Orders` AS T1 INNER JOIN `Sales Team` AS T2 ON T2.SalesTeamID = T1._SalesTeamID WHERE T2.`Sales Team` = 'Joshua Bennett'
Database: regional_sales
Tables: Customers, Products, Regions, Sales Team, Store Locations, Sales Orders
Columns (table index, column name): -1, *, 0, CustomerID, 0, Customer Names, 1, ProductID, 1, Product Name, 2, StateCode, 2, State, 2, Region, 3, SalesTeamID, 3, Sales Team, 3, Region, 4, StoreID, 4, City Name, 4, County, 4, StateCode, 4, State, 4, Type, 4, Latitude, 4, Longitude, 4, AreaCode, 4, Population, 4, Household Income, 4, Median Income, 4, Land Area, 4, Water Area, 4, Time Zone, 5, OrderNumber, 5, Sales Channel, 5, WarehouseCode, 5, ProcuredDate, 5, OrderDate, 5, ShipDate, 5, DeliveryDate, 5, CurrencyCode, 5, _SalesTeamID, 5, _CustomerID, 5, _StoreID, 5, _ProductID, 5, Order Quantity, 5, Discount Applied, 5, Unit Price, 5, Unit Cost
Question: Among the sales order shipped in July 2018, calculate the percentage of orders for home fragrances.
Evidence: shipped in July 2018 refers to ShipDate between 01-07-2018 and 31-07-2018; DIVIDE(COUNT(OrderNumber where Product Name = 'Home Fragrances' and SUBSTR(OrderDate, 1, 1) = '7'), COUNT(OrderNumber where SUBSTR(ShipDate, -2) = '18')) as percentage;
SQL: SELECT SUM(CASE WHEN T2.`Product Name` = 'Home Fragrances' THEN 1 ELSE 0 END) * 100 / COUNT(T1.OrderNumber)  FROM `Sales Orders` AS T1 INNER JOIN Products AS T2 ON T2.ProductID = T1._ProductID WHERE T1.ShipDate LIKE '7/%/18'
Database: regional_sales
Tables: Customers, Products, Regions, Sales Team, Store Locations, Sales Orders
Columns (table index, column name): -1, *, 0, CustomerID, 0, Customer Names, 1, ProductID, 1, Product Name, 2, StateCode, 2, State, 2, Region, 3, SalesTeamID, 3, Sales Team, 3, Region, 4, StoreID, 4, City Name, 4, County, 4, StateCode, 4, State, 4, Type, 4, Latitude, 4, Longitude, 4, AreaCode, 4, Population, 4, Household Income, 4, Median Income, 4, Land Area, 4, Water Area, 4, Time Zone, 5, OrderNumber, 5, Sales Channel, 5, WarehouseCode, 5, ProcuredDate, 5, OrderDate, 5, ShipDate, 5, DeliveryDate, 5, CurrencyCode, 5, _SalesTeamID, 5, _CustomerID, 5, _StoreID, 5, _ProductID, 5, Order Quantity, 5, Discount Applied, 5, Unit Price, 5, Unit Cost
Question: List down the customer IDs and names that start with alphabet "W".
Evidence: names that start with alphabet "W" refer to Customer Names LIKE 'W%';
SQL: SELECT DISTINCT CustomerID, `Customer Names` FROM Customers WHERE `Customer Names` LIKE 'W%' ORDER BY `Customer Names` DESC
Database: regional_sales
Tables: Customers, Products, Regions, Sales Team, Store Locations, Sales Orders
Columns (table index, column name): -1, *, 0, CustomerID, 0, Customer Names, 1, ProductID, 1, Product Name, 2, StateCode, 2, State, 2, Region, 3, SalesTeamID, 3, Sales Team, 3, Region, 4, StoreID, 4, City Name, 4, County, 4, StateCode, 4, State, 4, Type, 4, Latitude, 4, Longitude, 4, AreaCode, 4, Population, 4, Household Income, 4, Median Income, 4, Land Area, 4, Water Area, 4, Time Zone, 5, OrderNumber, 5, Sales Channel, 5, WarehouseCode, 5, ProcuredDate, 5, OrderDate, 5, ShipDate, 5, DeliveryDate, 5, CurrencyCode, 5, _SalesTeamID, 5, _CustomerID, 5, _StoreID, 5, _ProductID, 5, Order Quantity, 5, Discount Applied, 5, Unit Price, 5, Unit Cost
Question: List down the product IDs and names that include the word "Outdoor".
Evidence: names that include the word "Outdoor" refer to Product Name LIKE '%Outdoor%';
SQL: SELECT ProductID, T FROM ( SELECT ProductID , CASE  WHEN `Product Name` LIKE '%Outdoor%' THEN `Product Name` ELSE NULL END AS T FROM Products ) WHERE T IS NOT NULL ORDER BY T DESC
Database: regional_sales
Tables: Customers, Products, Regions, Sales Team, Store Locations, Sales Orders
Columns (table index, column name): -1, *, 0, CustomerID, 0, Customer Names, 1, ProductID, 1, Product Name, 2, StateCode, 2, State, 2, Region, 3, SalesTeamID, 3, Sales Team, 3, Region, 4, StoreID, 4, City Name, 4, County, 4, StateCode, 4, State, 4, Type, 4, Latitude, 4, Longitude, 4, AreaCode, 4, Population, 4, Household Income, 4, Median Income, 4, Land Area, 4, Water Area, 4, Time Zone, 5, OrderNumber, 5, Sales Channel, 5, WarehouseCode, 5, ProcuredDate, 5, OrderDate, 5, ShipDate, 5, DeliveryDate, 5, CurrencyCode, 5, _SalesTeamID, 5, _CustomerID, 5, _StoreID, 5, _ProductID, 5, Order Quantity, 5, Discount Applied, 5, Unit Price, 5, Unit Cost
Question: Among the sales with 40% discount via in-store channel, how many products were shipped from warehouse code of WARE-NMK1003?
Evidence: 40% discount refers to Discount Applied = 0.4; in-store channel refers to Sales Channel = 'In-Store'; orders refer to OrderNumber;
SQL: SELECT COUNT(DISTINCT T) FROM ( SELECT CASE  WHEN `Sales Channel` = 'In-Store' AND WarehouseCode = 'WARE-NMK1003' AND `Discount Applied` = '0.4' THEN OrderNumber ELSE NULL END AS T FROM `Sales Orders` ) WHERE T IS NOT NULL
Database: regional_sales
Tables: Customers, Products, Regions, Sales Team, Store Locations, Sales Orders
Columns (table index, column name): -1, *, 0, CustomerID, 0, Customer Names, 1, ProductID, 1, Product Name, 2, StateCode, 2, State, 2, Region, 3, SalesTeamID, 3, Sales Team, 3, Region, 4, StoreID, 4, City Name, 4, County, 4, StateCode, 4, State, 4, Type, 4, Latitude, 4, Longitude, 4, AreaCode, 4, Population, 4, Household Income, 4, Median Income, 4, Land Area, 4, Water Area, 4, Time Zone, 5, OrderNumber, 5, Sales Channel, 5, WarehouseCode, 5, ProcuredDate, 5, OrderDate, 5, ShipDate, 5, DeliveryDate, 5, CurrencyCode, 5, _SalesTeamID, 5, _CustomerID, 5, _StoreID, 5, _ProductID, 5, Order Quantity, 5, Discount Applied, 5, Unit Price, 5, Unit Cost
Question: Mention the most populated city and median income of the store in Florida state.
Evidence: most populated refers to Max(Population);
SQL: SELECT `City Name`, `Median Income` FROM `Store Locations` WHERE State = 'Florida' ORDER BY Population DESC LIMIT 1
Database: regional_sales
Tables: Customers, Products, Regions, Sales Team, Store Locations, Sales Orders
Columns (table index, column name): -1, *, 0, CustomerID, 0, Customer Names, 1, ProductID, 1, Product Name, 2, StateCode, 2, State, 2, Region, 3, SalesTeamID, 3, Sales Team, 3, Region, 4, StoreID, 4, City Name, 4, County, 4, StateCode, 4, State, 4, Type, 4, Latitude, 4, Longitude, 4, AreaCode, 4, Population, 4, Household Income, 4, Median Income, 4, Land Area, 4, Water Area, 4, Time Zone, 5, OrderNumber, 5, Sales Channel, 5, WarehouseCode, 5, ProcuredDate, 5, OrderDate, 5, ShipDate, 5, DeliveryDate, 5, CurrencyCode, 5, _SalesTeamID, 5, _CustomerID, 5, _StoreID, 5, _ProductID, 5, Order Quantity, 5, Discount Applied, 5, Unit Price, 5, Unit Cost
Question: Describe the ID, city and region of the stores which are in Allen country.
Evidence: ID refers to StoreID;
SQL: SELECT DISTINCT T2.StoreID, T2.`City Name`, T1.Region FROM Regions AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StateCode = T1.StateCode WHERE T2.County = 'Allen County'
Database: regional_sales
Tables: Customers, Products, Regions, Sales Team, Store Locations, Sales Orders
Columns (table index, column name): -1, *, 0, CustomerID, 0, Customer Names, 1, ProductID, 1, Product Name, 2, StateCode, 2, State, 2, Region, 3, SalesTeamID, 3, Sales Team, 3, Region, 4, StoreID, 4, City Name, 4, County, 4, StateCode, 4, State, 4, Type, 4, Latitude, 4, Longitude, 4, AreaCode, 4, Population, 4, Household Income, 4, Median Income, 4, Land Area, 4, Water Area, 4, Time Zone, 5, OrderNumber, 5, Sales Channel, 5, WarehouseCode, 5, ProcuredDate, 5, OrderDate, 5, ShipDate, 5, DeliveryDate, 5, CurrencyCode, 5, _SalesTeamID, 5, _CustomerID, 5, _StoreID, 5, _ProductID, 5, Order Quantity, 5, Discount Applied, 5, Unit Price, 5, Unit Cost
Question: List the ID, city, state and region for the store type which is fewer between borough and CDP.
Evidence: COUNT(StoreID) < COUNT(StoreID where Type = 'Borough') < COUNT(StoreID where Type = 'CDP');
SQL: SELECT DISTINCT T2.StoreID, T2.`City Name`, T1.State, T2.Type FROM Regions AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StateCode = T1.StateCode WHERE T2.Type = 'Borough' OR T2.Type = 'CDP'
Database: regional_sales
Tables: Customers, Products, Regions, Sales Team, Store Locations, Sales Orders
Columns (table index, column name): -1, *, 0, CustomerID, 0, Customer Names, 1, ProductID, 1, Product Name, 2, StateCode, 2, State, 2, Region, 3, SalesTeamID, 3, Sales Team, 3, Region, 4, StoreID, 4, City Name, 4, County, 4, StateCode, 4, State, 4, Type, 4, Latitude, 4, Longitude, 4, AreaCode, 4, Population, 4, Household Income, 4, Median Income, 4, Land Area, 4, Water Area, 4, Time Zone, 5, OrderNumber, 5, Sales Channel, 5, WarehouseCode, 5, ProcuredDate, 5, OrderDate, 5, ShipDate, 5, DeliveryDate, 5, CurrencyCode, 5, _SalesTeamID, 5, _CustomerID, 5, _StoreID, 5, _ProductID, 5, Order Quantity, 5, Discount Applied, 5, Unit Price, 5, Unit Cost
Question: Write down the region and name of the sale team ID of 18 and compare their orders between in-store and online.
Evidence: sale team ID of 18 refers to _SalesTeamID = 18; COUNT(OrderNumber where Sales Channel = 'In-Store') > COUNT(OrderNumber where Sales Channel = 'Online');
SQL: SELECT T2.Region, T2.`Sales Team` FROM `Sales Orders` AS T1 INNER JOIN `Sales Team` AS T2 ON T2.SalesTeamID = T1._SalesTeamID WHERE T2.SalesTeamID = 18 AND T1.`Sales Channel` = 'In-Store' OR T1.`Sales Channel` = 'Online'
Database: regional_sales
Tables: Customers, Products, Regions, Sales Team, Store Locations, Sales Orders
Columns (table index, column name): -1, *, 0, CustomerID, 0, Customer Names, 1, ProductID, 1, Product Name, 2, StateCode, 2, State, 2, Region, 3, SalesTeamID, 3, Sales Team, 3, Region, 4, StoreID, 4, City Name, 4, County, 4, StateCode, 4, State, 4, Type, 4, Latitude, 4, Longitude, 4, AreaCode, 4, Population, 4, Household Income, 4, Median Income, 4, Land Area, 4, Water Area, 4, Time Zone, 5, OrderNumber, 5, Sales Channel, 5, WarehouseCode, 5, ProcuredDate, 5, OrderDate, 5, ShipDate, 5, DeliveryDate, 5, CurrencyCode, 5, _SalesTeamID, 5, _CustomerID, 5, _StoreID, 5, _ProductID, 5, Order Quantity, 5, Discount Applied, 5, Unit Price, 5, Unit Cost
Question: Calculate the percentage of order via in-store channel of customer "Medline".
Evidence: Medline is the name of the customer; DIVIDE(COUNT(OrderNumber where Sales Channel = 'In-Store' and Customer Names = 'Medline'), COUNT(OrderNumber where Customer Names = 'Medline')) as percentage;
SQL: SELECT CAST(SUM(CASE WHEN T1.`Sales Channel` = 'In-Store' THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(T1._CustomerID) FROM `Sales Orders` AS T1 INNER JOIN Customers AS T2 ON T2.CustomerID = T1._CustomerID WHERE T2.`Customer Names` = 'Medline '
Database: regional_sales
Tables: Customers, Products, Regions, Sales Team, Store Locations, Sales Orders
Columns (table index, column name): -1, *, 0, CustomerID, 0, Customer Names, 1, ProductID, 1, Product Name, 2, StateCode, 2, State, 2, Region, 3, SalesTeamID, 3, Sales Team, 3, Region, 4, StoreID, 4, City Name, 4, County, 4, StateCode, 4, State, 4, Type, 4, Latitude, 4, Longitude, 4, AreaCode, 4, Population, 4, Household Income, 4, Median Income, 4, Land Area, 4, Water Area, 4, Time Zone, 5, OrderNumber, 5, Sales Channel, 5, WarehouseCode, 5, ProcuredDate, 5, OrderDate, 5, ShipDate, 5, DeliveryDate, 5, CurrencyCode, 5, _SalesTeamID, 5, _CustomerID, 5, _StoreID, 5, _ProductID, 5, Order Quantity, 5, Discount Applied, 5, Unit Price, 5, Unit Cost
Question: Describe the customer names and lasting delivery periods for the product of "Bedroom Furniture" by wholesale channel in 2019.
Evidence: delivery period in 2019 means time between placing of an order and the receipt of product and refers to SUBTRACT(DeliveryDate, OrderDate) where SUBSTR(OrderDate, -2 ) = '19'; Sales Channel = 'Wholesale'; Product Name = 'Bedroom Furniture';
SQL: SELECT T1.`Customer Names`, T2.DeliveryDate FROM Customers AS T1 INNER JOIN `Sales Orders` AS T2 ON T2._CustomerID = T1.CustomerID INNER JOIN Products AS T3 ON T3.ProductID = T2._ProductID WHERE T2.`Sales Channel` = 'Wholesale' AND T3.`Product Name` = 'Bedroom Furniture' AND T2.OrderDate LIKE '%/%/19'
Database: regional_sales
Tables: Customers, Products, Regions, Sales Team, Store Locations, Sales Orders
Columns (table index, column name): -1, *, 0, CustomerID, 0, Customer Names, 1, ProductID, 1, Product Name, 2, StateCode, 2, State, 2, Region, 3, SalesTeamID, 3, Sales Team, 3, Region, 4, StoreID, 4, City Name, 4, County, 4, StateCode, 4, State, 4, Type, 4, Latitude, 4, Longitude, 4, AreaCode, 4, Population, 4, Household Income, 4, Median Income, 4, Land Area, 4, Water Area, 4, Time Zone, 5, OrderNumber, 5, Sales Channel, 5, WarehouseCode, 5, ProcuredDate, 5, OrderDate, 5, ShipDate, 5, DeliveryDate, 5, CurrencyCode, 5, _SalesTeamID, 5, _CustomerID, 5, _StoreID, 5, _ProductID, 5, Order Quantity, 5, Discount Applied, 5, Unit Price, 5, Unit Cost
Question: Describe the customer names and product names which had over 3800 USD in net profit.
Evidence: over 3800 USD in net profit refers to SUBTRACT(Unit Price, Unit Cost) where Net Profit > 3800;
SQL: SELECT DISTINCT `Customer Names`, `Product Name` FROM ( SELECT T1.`Customer Names`, T3.`Product Name` , REPLACE(T2.`Unit Price`, ',', '') - REPLACE(T2.`Unit Cost`, ',', '') AS T FROM Customers T1 INNER JOIN `Sales Orders` T2 ON T2._CustomerID = T1.CustomerID INNER JOIN Products T3 ON T3.ProductID = T2._ProductID ) WHERE T > 3800
Database: regional_sales
Tables: Customers, Products, Regions, Sales Team, Store Locations, Sales Orders
Columns (table index, column name): -1, *, 0, CustomerID, 0, Customer Names, 1, ProductID, 1, Product Name, 2, StateCode, 2, State, 2, Region, 3, SalesTeamID, 3, Sales Team, 3, Region, 4, StoreID, 4, City Name, 4, County, 4, StateCode, 4, State, 4, Type, 4, Latitude, 4, Longitude, 4, AreaCode, 4, Population, 4, Household Income, 4, Median Income, 4, Land Area, 4, Water Area, 4, Time Zone, 5, OrderNumber, 5, Sales Channel, 5, WarehouseCode, 5, ProcuredDate, 5, OrderDate, 5, ShipDate, 5, DeliveryDate, 5, CurrencyCode, 5, _SalesTeamID, 5, _CustomerID, 5, _StoreID, 5, _ProductID, 5, Order Quantity, 5, Discount Applied, 5, Unit Price, 5, Unit Cost
Question: List the store located cities with regions in no water area of California state.
Evidence: cities refer to City Name; no water area refers to Water Area = 0;
SQL: SELECT DISTINCT T2.`City Name` FROM Regions AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StateCode = T1.StateCode WHERE T2.State = 'California' AND T2.`Water Area` = '0'
Database: regional_sales
Tables: Customers, Products, Regions, Sales Team, Store Locations, Sales Orders
Columns (table index, column name): -1, *, 0, CustomerID, 0, Customer Names, 1, ProductID, 1, Product Name, 2, StateCode, 2, State, 2, Region, 3, SalesTeamID, 3, Sales Team, 3, Region, 4, StoreID, 4, City Name, 4, County, 4, StateCode, 4, State, 4, Type, 4, Latitude, 4, Longitude, 4, AreaCode, 4, Population, 4, Household Income, 4, Median Income, 4, Land Area, 4, Water Area, 4, Time Zone, 5, OrderNumber, 5, Sales Channel, 5, WarehouseCode, 5, ProcuredDate, 5, OrderDate, 5, ShipDate, 5, DeliveryDate, 5, CurrencyCode, 5, _SalesTeamID, 5, _CustomerID, 5, _StoreID, 5, _ProductID, 5, Order Quantity, 5, Discount Applied, 5, Unit Price, 5, Unit Cost
Question: Calculate the order percentage by "Carlos Miller" sales team.
Evidence: DIVIDE(COUNT(OrderNumber where Sales Team = 'Carlos Miller'), COUNT(OrderNumber)) as percentage;
SQL: SELECT CAST(SUM(CASE WHEN T2.`Sales Team` = 'Carlos Miller' THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(T1.OrderNumber) FROM `Sales Orders` AS T1 INNER JOIN `Sales Team` AS T2 ON T2.SalesTeamID = T1._SalesTeamID
Database: regional_sales
Tables: Customers, Products, Regions, Sales Team, Store Locations, Sales Orders
Columns (table index, column name): -1, *, 0, CustomerID, 0, Customer Names, 1, ProductID, 1, Product Name, 2, StateCode, 2, State, 2, Region, 3, SalesTeamID, 3, Sales Team, 3, Region, 4, StoreID, 4, City Name, 4, County, 4, StateCode, 4, State, 4, Type, 4, Latitude, 4, Longitude, 4, AreaCode, 4, Population, 4, Household Income, 4, Median Income, 4, Land Area, 4, Water Area, 4, Time Zone, 5, OrderNumber, 5, Sales Channel, 5, WarehouseCode, 5, ProcuredDate, 5, OrderDate, 5, ShipDate, 5, DeliveryDate, 5, CurrencyCode, 5, _SalesTeamID, 5, _CustomerID, 5, _StoreID, 5, _ProductID, 5, Order Quantity, 5, Discount Applied, 5, Unit Price, 5, Unit Cost
Question: Compare the number of orders between "Platters" and "Serveware" products.
Evidence: COUNT(OrderNumber where Product Name = 'Platters') > COUNT(OrderNumber where Product Name = 'Serveware');
SQL: SELECT SUM(CASE WHEN T2.`Product Name` = 'Platters' THEN 1 ELSE 0 END) AS num1 , SUM(CASE WHEN T2.`Product Name` = 'Serveware' THEN 1 ELSE 0 END) AS num2 FROM `Sales Orders` AS T1 INNER JOIN Products AS T2 ON T2.ProductID = T1._ProductID
Database: regional_sales
Tables: Customers, Products, Regions, Sales Team, Store Locations, Sales Orders
Columns (table index, column name): -1, *, 0, CustomerID, 0, Customer Names, 1, ProductID, 1, Product Name, 2, StateCode, 2, State, 2, Region, 3, SalesTeamID, 3, Sales Team, 3, Region, 4, StoreID, 4, City Name, 4, County, 4, StateCode, 4, State, 4, Type, 4, Latitude, 4, Longitude, 4, AreaCode, 4, Population, 4, Household Income, 4, Median Income, 4, Land Area, 4, Water Area, 4, Time Zone, 5, OrderNumber, 5, Sales Channel, 5, WarehouseCode, 5, ProcuredDate, 5, OrderDate, 5, ShipDate, 5, DeliveryDate, 5, CurrencyCode, 5, _SalesTeamID, 5, _CustomerID, 5, _StoreID, 5, _ProductID, 5, Order Quantity, 5, Discount Applied, 5, Unit Price, 5, Unit Cost
Question: Calculate the total net profit of the store located in highest median income city.
Evidence: net profit can be computed as SUBTRACT(Unit Price, Unit Cost); highest median income city refers to City Name where MAX(Median Income);
SQL: SELECT SUM(REPLACE(T1.`Unit Price`, ',', '') - REPLACE(T1.`Unit Cost`, ',', '')) FROM `Sales Orders` AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StoreID = T1._StoreID ORDER BY T2.`Median Income` DESC LIMIT 1
Database: regional_sales
Tables: Customers, Products, Regions, Sales Team, Store Locations, Sales Orders
Columns (table index, column name): -1, *, 0, CustomerID, 0, Customer Names, 1, ProductID, 1, Product Name, 2, StateCode, 2, State, 2, Region, 3, SalesTeamID, 3, Sales Team, 3, Region, 4, StoreID, 4, City Name, 4, County, 4, StateCode, 4, State, 4, Type, 4, Latitude, 4, Longitude, 4, AreaCode, 4, Population, 4, Household Income, 4, Median Income, 4, Land Area, 4, Water Area, 4, Time Zone, 5, OrderNumber, 5, Sales Channel, 5, WarehouseCode, 5, ProcuredDate, 5, OrderDate, 5, ShipDate, 5, DeliveryDate, 5, CurrencyCode, 5, _SalesTeamID, 5, _CustomerID, 5, _StoreID, 5, _ProductID, 5, Order Quantity, 5, Discount Applied, 5, Unit Price, 5, Unit Cost
Question: Among the sales team in South region, write down the numbers of orders made by the sales team ID of one digit.
Evidence: sales team ID of one digit refers to _SalesTeamID BETWEEN 1 AND 9; numbers of orders refer to COUNT(OrderNumber);
SQL: SELECT COUNT(T1.OrderNumber) FROM `Sales Orders` AS T1 INNER JOIN `Sales Team` AS T2 ON T2.SalesTeamID = T1._SalesTeamID WHERE T2.Region = 'South' AND T2.SalesTeamID BETWEEN 1 AND 9 GROUP BY T2.SalesTeamID HAVING COUNT(T1.OrderNumber)
Database: regional_sales
Tables: Customers, Products, Regions, Sales Team, Store Locations, Sales Orders
Columns (table index, column name): -1, *, 0, CustomerID, 0, Customer Names, 1, ProductID, 1, Product Name, 2, StateCode, 2, State, 2, Region, 3, SalesTeamID, 3, Sales Team, 3, Region, 4, StoreID, 4, City Name, 4, County, 4, StateCode, 4, State, 4, Type, 4, Latitude, 4, Longitude, 4, AreaCode, 4, Population, 4, Household Income, 4, Median Income, 4, Land Area, 4, Water Area, 4, Time Zone, 5, OrderNumber, 5, Sales Channel, 5, WarehouseCode, 5, ProcuredDate, 5, OrderDate, 5, ShipDate, 5, DeliveryDate, 5, CurrencyCode, 5, _SalesTeamID, 5, _CustomerID, 5, _StoreID, 5, _ProductID, 5, Order Quantity, 5, Discount Applied, 5, Unit Price, 5, Unit Cost
Question: How many orders have order date in 5/31/2018?
Evidence: orders refer to OrderNumber;
SQL: SELECT SUM(IIF(OrderDate = '5/31/18', 1, 0)) FROM `Sales Orders`
Database: regional_sales
Tables: Customers, Products, Regions, Sales Team, Store Locations, Sales Orders
Columns (table index, column name): -1, *, 0, CustomerID, 0, Customer Names, 1, ProductID, 1, Product Name, 2, StateCode, 2, State, 2, Region, 3, SalesTeamID, 3, Sales Team, 3, Region, 4, StoreID, 4, City Name, 4, County, 4, StateCode, 4, State, 4, Type, 4, Latitude, 4, Longitude, 4, AreaCode, 4, Population, 4, Household Income, 4, Median Income, 4, Land Area, 4, Water Area, 4, Time Zone, 5, OrderNumber, 5, Sales Channel, 5, WarehouseCode, 5, ProcuredDate, 5, OrderDate, 5, ShipDate, 5, DeliveryDate, 5, CurrencyCode, 5, _SalesTeamID, 5, _CustomerID, 5, _StoreID, 5, _ProductID, 5, Order Quantity, 5, Discount Applied, 5, Unit Price, 5, Unit Cost
Question: List out the name of orders which have delivery date of 6/13/2018.
SQL: SELECT DISTINCT T FROM ( SELECT IIF(DeliveryDate = '6/13/18', OrderNumber, NULL) AS T FROM `Sales Orders` ) WHERE T IS NOT NULL