input
stringlengths 236
16.9k
| output
stringlengths 19
805
|
---|---|
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- List the store located cities with regions in no water area of California state.
| 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 schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Calculate the order percentage by "Carlos Miller" sales team.
| 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 schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Compare the number of orders between "Platters" and "Serveware" products.
| 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 schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Calculate the total net profit of the store located in highest median income city.
| 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 schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Among the sales team in South region, write down the numbers of orders made by the sales team ID of one digit.
| 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 schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- How many orders have order date in 5/31/2018?
| SELECT SUM(IIF(OrderDate = '5/31/18', 1, 0)) FROM `Sales Orders`; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- List out the name of orders which have delivery date of 6/13/2018.
| SELECT DISTINCT T FROM ( SELECT IIF(DeliveryDate = '6/13/18', OrderNumber, NULL) AS T FROM `Sales Orders` ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- How many orders placed were with more than 5 product quantities?
| SELECT SUM(IIF(`Order Quantity` > 5, 1, 0)) FROM `Sales Orders`; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- State the full name of state code "GA".
| SELECT T FROM ( SELECT IIF(StateCode = 'GA', State, NULL) AS T FROM Regions ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- How many states located in the Midwest region?
| SELECT COUNT(DISTINCT T) FROM ( SELECT CASE WHEN Region = 'Midwest' THEN StateCode ELSE NULL END AS T FROM Regions ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- List out the product name of order which has unit cost of 781.22.
| SELECT T FROM ( SELECT DISTINCT IIF(T1.`Unit Cost` = 781.22, T2.`Product Name`, NULL) AS T FROM `Sales Orders` T1 INNER JOIN Products T2 ON T2.ProductID = T1._ProductID ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- State the delivery date of cookware.
| SELECT T FROM ( SELECT DISTINCT IIF(T2.`Product Name` = 'Cookware', T1.DeliveryDate, NULL) AS T FROM `Sales Orders` T1 INNER JOIN Products T2 ON T2.ProductID = T1._ProductID ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- How many furniture cushions orders which have date of order in 2018?
| SELECT SUM(CASE WHEN T1.OrderDate LIKE '%/%/18' AND T2.`Product Name` = 'Furniture Cushions' THEN 1 ELSE 0 END) FROM `Sales Orders` AS T1 INNER JOIN Products AS T2 ON T2.ProductID = T1._ProductID; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- List out the name of products which have been applied 10% discount.
| SELECT T FROM ( SELECT DISTINCT IIF(T1.`Discount Applied` = 0.1, T2.`Product Name`, NULL) AS T FROM `Sales Orders` T1 INNER JOIN Products T2 ON T2.ProductID = T1._ProductID ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Calculate the average net profit of phones which have sales channel of distributor.
| SELECT SUM(REPLACE(T1.`Unit Price`, ',', '') - REPLACE(T1.`Unit Cost`, ',', '')) / COUNT(T1.OrderNumber) FROM `Sales Orders` AS T1 INNER JOIN Products AS T2 ON T2.ProductID = T1._ProductID WHERE T2.`Product Name` = 'Phones' AND T1.`Sales Channel` = 'Distributor'; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Calculate the average net profit of bar tools which has ordered quantity exceed 5.
| SELECT SUM(REPLACE(T1.`Unit Price`, ',', '') - REPLACE(T1.`Unit Cost`, ',', '')) / COUNT(T1.OrderNumber) FROM `Sales Orders` AS T1 INNER JOIN Products AS T2 ON T2.ProductID = T1._ProductID WHERE T2.`Product Name` = 'Bar Tools' AND T1.`Order Quantity` > 5; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- List out the city name of states located in South region.
| SELECT T FROM ( SELECT DISTINCT CASE WHEN T1.Region = 'South' THEN T2.`City Name` END AS T FROM Regions T1 INNER JOIN `Store Locations` T2 ON T2.StateCode = T1.StateCode ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- What is the region of stores which have type of "Town" in the list?
| SELECT T FROM ( SELECT DISTINCT CASE WHEN T2.Type = 'Town' THEN T1.Region END AS T FROM Regions T1 INNER JOIN `Store Locations` T2 ON T2.StateCode = T1.StateCode ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- How many orders that Medsep Group had made?
| SELECT SUM(CASE WHEN T1.`Customer Names` = 'Medsep Group' THEN 1 ELSE 0 END) FROM Customers AS T1 INNER JOIN `Sales Orders` AS T2 ON T2._CustomerID = T1.CustomerID; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- List out the discount levels applied for all orders from Ole Group.
| SELECT T FROM ( SELECT DISTINCT CASE WHEN T1.`Customer Names` = 'Ole Group' THEN T2.`Discount Applied` END AS T FROM Customers T1 INNER JOIN `Sales Orders` T2 ON T2._CustomerID = T1.CustomerID ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- State the customer name of orders which has shipped date in 7/8/2018.
| SELECT T FROM ( SELECT DISTINCT CASE WHEN T2.ShipDate = '7/8/18' THEN T1.`Customer Names` END AS T FROM Customers T1 INNER JOIN `Sales Orders` T2 ON T2._CustomerID = T1.CustomerID ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Among the orders placed by Ei, how many orders have quantity greater than 4?
| SELECT SUM(CASE WHEN T1.`Order Quantity` > 4 AND T2.`Customer Names` = 'Ei ' THEN 1 ELSE 0 END) FROM `Sales Orders` AS T1 INNER JOIN Customers AS T2 ON T2.CustomerID = T1._CustomerID; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Among the orders placed by Pacific Ltd, how many orders have been applied 5% discount ?
| SELECT SUM(CASE WHEN T1.`Discount Applied` = 0.05 AND T2.`Customer Names` = 'Pacific Ltd' THEN 1 ELSE 0 END) FROM `Sales Orders` AS T1 INNER JOIN Customers AS T2 ON T2.CustomerID = T1._CustomerID; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- What is the customer names of orders which have unit cost greater than 4000USD?
| SELECT T FROM ( SELECT DISTINCT CASE WHEN T2.`Unit Cost` > 4000 THEN T1.`Customer Names` END AS T FROM Customers T1 INNER JOIN `Sales Orders` T2 ON T2._CustomerID = T1.CustomerID ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Please list the id and detailed position of all stores in Birmingham city.
| SELECT StoreID, Latitude, Longitude FROM `Store Locations` WHERE `City Name` = 'Birmingham'; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Which city has the largest population?
| SELECT `City Name` FROM `Store Locations` ORDER BY Population DESC LIMIT 1; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- How many CDP stores are there in California?
| SELECT SUM(CASE WHEN State = 'California' AND Type = 'CDP' THEN 1 ELSE 0 END) FROM `Store Locations`; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Please give the order number and product name of the order which has the lowest unit price.
| SELECT T1.OrderNumber, T2.`Product Name` FROM `Sales Orders` AS T1 INNER JOIN Products AS T2 ON T2.ProductID = T1._ProductID WHERE REPLACE(T1.`Unit Price`, ',', '') = ( SELECT REPLACE(T1.`Unit Price`, ',', '') FROM `Sales Orders` AS T1 INNER JOIN Products AS T2 ON T2.ProductID = T1._ProductID ORDER BY REPLACE(T1.`Unit Price`, ',', '') LIMIT 1 ); |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Which product has the highest net profit in 2019?
| SELECT T2.`Product Name` FROM `Sales Orders` AS T1 INNER JOIN Products AS T2 ON T2.ProductID = T1._ProductID WHERE T1.OrderDate LIKE '%/%/19' ORDER BY REPLACE(T1.`Unit Price`, ',', '') - REPLACE(T1.`Unit Cost`, ',', '') DESC LIMIT 1; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- What is the average unit price of a Cookware product?
| SELECT AVG(REPLACE(T1.`Unit Price`, ',', '')) FROM `Sales Orders` AS T1 INNER JOIN Products AS T2 ON T2.ProductID = T1._ProductID WHERE T2.`Product Name` = 'Cookware'; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Please list all sale team names which had orders on 5/31/2018.
| SELECT T FROM ( SELECT DISTINCT CASE WHEN T1.OrderDate = '5/31/18' THEN T2.`Sales Team` ELSE NULL END AS T FROM `Sales Orders` T1 INNER JOIN `Sales Team` T2 ON T2.SalesTeamID = T1._SalesTeamID ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Which sales team name has the least orders in 2019?
| SELECT T2.`Sales Team` FROM `Sales Orders` AS T1 INNER JOIN `Sales Team` AS T2 ON T2.SalesTeamID = T1._SalesTeamID WHERE T1.OrderDate LIKE '%/%/19' GROUP BY T2.`Sales Team` ORDER BY COUNT(T1.OrderNumber) ASC LIMIT 1; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- From 2018 to 2020, which year did the George Lewis group have the highest number of orders?
| SELECT SUBSTR(T1.OrderDate, -2, 2) FROM `Sales Orders` AS T1 INNER JOIN `Sales Team` AS T2 ON T2.SalesTeamID = T1._SalesTeamID WHERE T2.`Sales Team` = 'George Lewis' GROUP BY SUBSTR(T1.OrderDate, -2, 2) ORDER BY COUNT(T1.OrderNumber) DESC LIMIT 1; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- What is the percentage of total orders from stores in Orange County in 2018?
| SELECT CAST(SUM(CASE WHEN T2.County = 'Orange County' THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(T1.OrderNumber) FROM `Sales Orders` AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StoreID = T1._StoreID WHERE T1.OrderDate LIKE '%/%/18'; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Which order number has the highest unit price?
| SELECT OrderNumber FROM `Sales Orders` WHERE REPLACE(`Unit Price`, ',', '') = ( SELECT REPLACE(`Unit Price`, ',', '') FROM `Sales Orders` ORDER BY REPLACE(`Unit Price`, ',', '') DESC LIMIT 1 ); |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Which sales team id has the highest number of orders in 2018?
| SELECT _SalesTeamID FROM `Sales Orders` WHERE OrderDate LIKE '%/%/18' GROUP BY _SalesTeamID ORDER BY COUNT(_SalesTeamID) DESC LIMIT 1; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- What is the unit cost of order SO - 000103?
| SELECT DISTINCT T FROM ( SELECT IIF(OrderNumber = 'SO - 000103', `Unit Cost`, NULL) AS T FROM `Sales Orders` ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- In 2020, what were the total orders of all stores in Maricopa County?
| SELECT SUM(CASE WHEN T2.County = 'Maricopa County' AND OrderDate LIKE '%/%/20' THEN 1 ELSE 0 END) FROM `Sales Orders` AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StoreID = T1._StoreID; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- What is the detailed position of the store which has order SO - 000115?
| SELECT T2.Latitude, T2.Longitude FROM `Sales Orders` AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StoreID = T1._StoreID WHERE T1.OrderNumber = 'SO - 000115'; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Please calculate the total number of orders by each city in 2019.
| SELECT COUNT(T1.OrderNumber) FROM `Sales Orders` AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StoreID = T1._StoreID WHERE T1.OrderDate LIKE '%/%/19' GROUP BY T2.`City Name` HAVING COUNT(T1.OrderNumber); |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Please list the names of customers who have total orders of over 3 in 2018.
| SELECT DISTINCT IIF(COUNT(T2.CustomerID) > 3, T2.`Customer Names`, NULL) FROM `Sales Orders` AS T1 INNER JOIN Customers AS T2 ON T2.CustomerID = T1._CustomerID WHERE T1.OrderDate LIKE '%/%/18' GROUP BY T1._CustomerID HAVING COUNT(T2.CustomerID); |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- What were the total orders of Medsep Group from 2018 to 2020?
| SELECT SUM(CASE WHEN SUBSTR(T1.OrderDate, -2) IN ('18', '19', '20') AND T2.`Customer Names` = 'Medsep Group' THEN 1 ELSE 0 END) FROM `Sales Orders` AS T1 INNER JOIN Customers AS T2 ON T2.CustomerID = T1._CustomerID; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Please list the customer names whose order quantity was more than 5 on 6/1/2018.
| SELECT T FROM ( SELECT DISTINCT CASE WHEN SUM(T1.`Order Quantity`) > 5 THEN T2.`Customer Names` END AS T FROM `Sales Orders` T1 INNER JOIN Customers T2 ON T2.CustomerID = T1._CustomerID WHERE T1.OrderDate = '6/1/18' GROUP BY T1._CustomerID ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- What is the percentage of total orders of Stephen Payne that had a net profit of over 1000?
| SELECT CAST(SUM(CASE WHEN REPLACE(T1.`Unit Price`, ',', '') - REPLACE(T1.`Unit Cost`, ',', '') > 1000 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 WHERE T2.`Sales Team` = 'Stephen Payne'; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- How many sales team were from Northeast?
| SELECT SUM(CASE WHEN Region = 'Northeast' THEN 1 ELSE 0 END) FROM `Sales Team`; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- State the name of all city in Maricopa County along with its latitude and longitude.
| SELECT DISTINCT `City Name`, Latitude, Longitude FROM `Store Locations` WHERE County = 'Maricopa County'; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Which order have the highest unit cost?
| SELECT OrderNumber FROM `Sales Orders` WHERE REPLACE(`Unit Cost`, ',', '') = ( SELECT REPLACE(`Unit Cost`, ',', '') FROM `Sales Orders` ORDER BY REPLACE(`Unit Cost`, ',', '') DESC LIMIT 1 ); |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- List all the name of products with the ID of 30 to 40.
| SELECT T FROM ( SELECT CASE WHEN ProductID BETWEEN 30 AND 40 THEN `Product Name` ELSE NULL END AS T FROM Products ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Calculate ratio between the highest unit cost and the lowest unit cost?
| SELECT ( SELECT REPLACE(`Unit Cost`, ',', '') FROM `Sales Orders` WHERE REPLACE(`Unit Cost`, ',', '') = ( SELECT REPLACE(`Unit Cost`, ',', '') FROM `Sales Orders` ORDER BY REPLACE(`Unit Cost`, ',', '') DESC LIMIT 1 ) ORDER BY REPLACE(`Unit Cost`, ',', '') DESC LIMIT 1 ) / ( SELECT REPLACE(`Unit Cost`, ',', '') FROM `Sales Orders` WHERE REPLACE(`Unit Cost`, ',', '') = ( SELECT REPLACE(`Unit Cost`, ',', '') FROM `Sales Orders` ORDER BY REPLACE(`Unit Cost`, ',', '') ASC LIMIT 1 ) ORDER BY REPLACE(`Unit Cost`, ',', '') ASC LIMIT 1 ); |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Which product was ordered the most in 2018?
| SELECT T2.`Product Name` FROM `Sales Orders` AS T1 INNER JOIN Products AS T2 ON T2.ProductID = T1._ProductID WHERE T1.OrderDate LIKE '%/%/18' GROUP BY T1._ProductID ORDER BY COUNT(T1._ProductID) DESC LIMIT 1; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- How many products sold by Adam Hernandez?
| SELECT SUM(CASE WHEN T2.`Sales Team` = 'Adam Hernandez' THEN 1 ELSE 0 END) FROM `Sales Orders` AS T1 INNER JOIN `Sales Team` AS T2 ON T2.SalesTeamID = T1._SalesTeamID; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- List all orders where its products were shipped from Daly City.
| SELECT T FROM ( SELECT DISTINCT CASE WHEN T2.`City Name` = 'Daly City' THEN T1.OrderNumber END AS T FROM `Sales Orders` T1 INNER JOIN `Store Locations` T2 ON T2.StoreID = T1._StoreID ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- How many orders made by Rochester Ltd?
| SELECT SUM(CASE WHEN T1.`Customer Names` = 'Rochester Ltd' THEN 1 ELSE 0 END) FROM Customers AS T1 INNER JOIN `Sales Orders` AS T2 ON T2._CustomerID = T1.CustomerID; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- State the order number where Qualitest ordered the highest product quantity.
| SELECT T1.OrderNumber FROM `Sales Orders` AS T1 INNER JOIN Customers AS T2 ON T2.CustomerID = T1._CustomerID WHERE T2.`Customer Names` = 'Qualitest ' ORDER BY T1.`Order Quantity` DESC LIMIT 1; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- List the order for all in-store sales along with the products sold.
| SELECT DISTINCT T1.OrderNumber, T2.`Product Name` FROM `Sales Orders` AS T1 INNER JOIN Products AS T2 ON T2.ProductID = T1._ProductID WHERE T1.`Sales Channel` = 'In-Store'; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- How many online sales were made in May 2018 where products were shipped from Norman?
| SELECT SUM(CASE WHEN T1.OrderDate LIKE '5/%/18' AND T1.`Sales Channel` = 'Online' AND T2.`City Name` = 'Norman' THEN 1 ELSE 0 END) FROM `Sales Orders` AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StoreID = T1._StoreID; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Among the products sold in Maricopa County, which was the least sold?
| SELECT T1.`Product Name` FROM Products AS T1 INNER JOIN `Sales Orders` AS T2 ON T2._ProductID = T1.ProductID INNER JOIN `Store Locations` AS T3 ON T3.StoreID = T2._StoreID WHERE T3.County = 'Maricopa County' ORDER BY T2.`Order Quantity` ASC LIMIT 1; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- State all the order numbers for sales team of Samuel Fowler.
| SELECT T FROM ( SELECT DISTINCT CASE WHEN T2.`Sales Team` = 'Samuel Fowler' THEN T1.OrderNumber ELSE NULL END AS T FROM `Sales Orders` T1 INNER JOIN `Sales Team` T2 ON T2.SalesTeamID = T1._SalesTeamID ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Find the number of baseball ordered in December 2017.
| SELECT COUNT(T2.OrderNumber) FROM Products AS T1 INNER JOIN `Sales Orders` AS T2 ON T2._ProductID = T1.ProductID WHERE T1.`Product Name` = 'Baseball' AND T2.OrderDate LIKE '12/%/18'; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Find the average number of ornaments sold each month in 2018.
| SELECT CAST(SUM(T2.`Order Quantity`) AS REAL) / 12 FROM Products AS T1 INNER JOIN `Sales Orders` AS T2 ON T2._ProductID = T1.ProductID WHERE T1.`Product Name` = 'Ornaments' AND T2.OrderDate LIKE '%/%/18'; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Find the percentage of products that were shipped from Burbank in 2018?
| SELECT CAST(SUM(CASE WHEN T3.`City Name` = 'Burbank' THEN T2.`Order Quantity` ELSE 0 END) AS REAL) * 100 / SUM(T2.`Order Quantity`) FROM Products AS T1 INNER JOIN `Sales Orders` AS T2 ON T2._ProductID = T1.ProductID INNER JOIN `Store Locations` AS T3 ON T3.StoreID = T2._StoreID WHERE T2.OrderDate LIKE '%/%/18'; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- What is the difference in order number from "WARE-MKL1006" and "WARE-NBV1002"?
| SELECT SUM(IIF(WarehouseCode = 'WARE-MKL1006', 1, 0)) - SUM(IIF(WarehouseCode = 'WARE-NBV1002', 1, 0)) AS difference FROM `Sales Orders`; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Describe the product names delivered in 2021 for the customer "Sundial".
| SELECT T FROM ( SELECT DISTINCT CASE WHEN T2.DeliveryDate LIKE '%/%/21' AND T1.`Customer Names` = 'Sundial ' THEN T3.`Product Name` END 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 IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Write down the store IDs and region of the state "Michigan".
| SELECT DISTINCT T2.StoreID, T1.Region FROM Regions AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StateCode = T1.StateCode WHERE T2.State = 'Michigan'; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Compare the total number of orders between customer "Apollo Ltd" and "Pacific Ltd".
| SELECT SUM(CASE WHEN T2.`Customer Names` = 'Apollo Ltd' THEN 1 ELSE 0 END), SUM(CASE WHEN T2.`Customer Names` = 'Pacific Ltd' THEN 1 ELSE 0 END) FROM `Sales Orders` AS T1 INNER JOIN Customers AS T2 ON T2.CustomerID = T1._CustomerID; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Find the store ID with more orders between "Aurora" and "Babylon" city.
| SELECT T2.StoreID FROM `Sales Orders` AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StoreID = T1._StoreID WHERE T2.`City Name` = 'Aurora (Township)' OR T2.`City Name` = 'Babylon (Town)' GROUP BY T2.StoreID ORDER BY COUNT(T1.OrderNumber) DESC LIMIT 1; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- List down the customer names and product names of the order made by "Anthony Torres" via distributor channel.
| SELECT DISTINCT T1.`Customer Names`, T4.`Product Name` FROM Customers AS T1 INNER JOIN `Sales Orders` AS T2 ON T2._CustomerID = T1.CustomerID INNER JOIN `Sales Team` AS T3 ON T3.SalesTeamID = T2._SalesTeamID INNER JOIN Products AS T4 ON T4.ProductID = T2._ProductID WHERE T3.`Sales Team` = 'Anthony Torres' AND T2.`Sales Channel` = 'Distributor'; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Mention the customer names and IDs which ordered total net profit of above 5000 USD through online channel.
| SELECT DISTINCT `Customer Names`, CustomerID FROM ( SELECT T2.`Customer Names`, T2.CustomerID , SUM(REPLACE(T1.`Unit Price`, ',', '') - REPLACE(T1.`Unit Cost`, ',', '')) AS T FROM `Sales Orders` T1 INNER JOIN Customers T2 ON T2.CustomerID = T1._CustomerID WHERE T1.`Sales Channel` = 'Online' GROUP BY T2.CustomerID ) WHERE T > 5000; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Find the net profit of the floral products which were delivered in 2021.
| SELECT SUM(REPLACE(T1.`Unit Price`, ',', '') - REPLACE(T1.`Unit Cost`, ',', '')) FROM `Sales Orders` AS T1 INNER JOIN Products AS T2 ON T2.ProductID = T1._ProductID WHERE T1.DeliveryDate LIKE '%/%/21' AND T2.`Product Name` = 'Floral'; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Count the number of orders made from the store in city with population of 3000000 to 4000000.
| SELECT COUNT(T1.OrderNumber) FROM `Sales Orders` AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StoreID = T1._StoreID WHERE T2.Population BETWEEN 3000000 AND 4000000; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Name the products via wholesale channel of the store under Pacific/Honolulu time zone.
| SELECT T FROM ( SELECT DISTINCT CASE WHEN T3.`Time Zone` = 'Pacific/Honolulu' AND T2.`Sales Channel` = 'Wholesale' THEN T1.`Product Name` ELSE NULL END AS T FROM Products T1 INNER JOIN `Sales Orders` T2 ON T2._ProductID = T1.ProductID INNER JOIN `Store Locations` T3 ON T3.StoreID = T2._StoreID ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- List the order numbers and product names which were ordered on 6th June, 2018.
| SELECT DISTINCT OrderNumber, `Product Name` FROM ( SELECT IIF(T2.OrderDate = '6/6/18', T2.OrderNumber, NULL) AS "OrderNumber" , IIF(T2.OrderDate = '6/6/18', T1.`Product Name`, NULL) AS "Product Name" FROM Products T1 INNER JOIN `Sales Orders` T2 ON T2._ProductID = T1.ProductID ) WHERE OrderNumber IS NOT NULL AND `Product Name` IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Find the average yearly order by customer Weimei Corp for 2018, 2019 and 2020.
| SELECT COUNT(T1.OrderNumber) / 3 FROM `Sales Orders` AS T1 INNER JOIN Customers AS T2 ON T2.CustomerID = T1._CustomerID WHERE (T1.OrderDate LIKE '%/%/18' AND T2.`Customer Names` = 'Weimei Corp') OR (T1.OrderDate LIKE '%/%/19' AND T2.`Customer Names` = 'Weimei Corp') OR (T1.OrderDate LIKE '%/%/20' AND T2.`Customer Names` = 'Weimei Corp'); |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Calculate the average monthly order and percentage of warehouse "WARE-NMK1003" in 2019. Among them, mention number of orders for floor lamps.
| SELECT CAST(SUM(CASE WHEN T2.WarehouseCode = 'WARE-NMK1003' THEN 1 ELSE 0 END) AS REAL) / 12 , CAST(SUM(CASE WHEN T2.WarehouseCode = 'WARE-NMK1003' THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(T2.OrderNumber), COUNT(CASE WHEN T1.`Product Name` = 'Floor Lamps' AND T2.WarehouseCode = 'WARE-NMK1003' THEN T2.`Order Quantity` ELSE NULL END) FROM Products AS T1 INNER JOIN `Sales Orders` AS T2 ON T2._ProductID = T1.ProductID WHERE T2.OrderDate LIKE '%/%/19'; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Indicate the procured dates for the customer whose ID is 11.
| SELECT DISTINCT T FROM ( SELECT IIF(_CustomerID = 11, ProcuredDate, NULL) AS T FROM `Sales Orders` ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- How many orders through distributor were for the minimum quantity?
| SELECT SUM(CASE WHEN `Order Quantity` = 1 AND `Sales Channel` = 'Distributor' THEN 1 ELSE 0 END) FROM `Sales Orders`; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- List by ID all sales teams that have sold products at a 10% discount in store.
| 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 schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- How many Borough-type stores located in the city of Brooklyn have a population of less than 3 million?
| SELECT SUM(CASE WHEN Population < 3000000 AND Type = 'Borough' AND `City Name` = 'Brooklyn' THEN 1 ELSE 0 END) FROM `Store Locations`; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- How many states are in the Midwest region?
| 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 schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- What are the top 10 products with the highest net profit?
| SELECT T2.`Product Name` FROM `Sales Orders` AS T1 INNER JOIN Products AS T2 ON T2.ProductID = T1._ProductID GROUP BY T1._ProductID ORDER BY SUM(REPLACE(T1.`Unit Price`, ',', '') - REPLACE(T1.`Unit Cost`, ',', '')) DESC LIMIT 10; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Indicate the name of the customers who have placed an order of 3 units in February 2018.
| SELECT T FROM ( SELECT DISTINCT CASE WHEN T2.`Order Quantity` = 3 AND T2.OrderDate LIKE '2/%/18' THEN T1.`Customer Names` END AS T FROM Customers T1 INNER JOIN `Sales Orders` T2 ON T2._CustomerID = T1.CustomerID ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- What are the names of the sales teams that have served to customer Apotheca, Ltd?
| SELECT DISTINCT T3.`Sales Team` FROM Customers AS T1 INNER JOIN `Sales Orders` AS T2 ON T2._CustomerID = T1.CustomerID INNER JOIN `Sales Team` AS T3 ON T3.SalesTeamID = T2._SalesTeamID WHERE T1.`Customer Names` = 'Apotheca, Ltd'; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- In which regions are the stores that have shipped products through the WARE-UHY1004 warehouse?
| SELECT T FROM ( SELECT DISTINCT CASE WHEN T3.WarehouseCode = 'WARE-UHY1004' THEN T1.Region END AS T FROM Regions T1 INNER JOIN `Store Locations` T2 ON T2.StateCode = T1.StateCode INNER JOIN `Sales Orders` T3 ON T3._StoreID = T2.StoreID ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- List all the cities where Shawn Torres sells Audio products.
| SELECT T FROM ( SELECT DISTINCT CASE WHEN T4.`Product Name` = 'Audio' AND T3.`Sales Team` = 'Shawn Torres' THEN T1.`City Name` ELSE NULL END AS T FROM `Store Locations` T1 INNER JOIN `Sales Orders` T2 ON T2._StoreID = T1.StoreID INNER JOIN `Sales Team` T3 ON T3.SalesTeamID = T2._SalesTeamID INNER JOIN Products T4 ON T4.ProductID = T2._ProductID ) WHERE T IS NOT NULL; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- Lists the name of the product and customer who placed an order on 10/21/18 and it was delivered on 11/21/19.
| SELECT T3.`Product Name`, T1.`Customer Names` 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.OrderDate = '10/21/18' AND T2.DeliveryDate = '11/21/19'; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- How many stores procured products on October 27, 2018, in the city of Oregon?
| SELECT SUM(CASE WHEN T1.ProcuredDate = '10/27/18' AND T2.`City Name` = 'Orlando' THEN 1 ELSE 0 END) FROM `Sales Orders` AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StoreID = T1._StoreID; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- What sales channels are used the most in the 3 places with the highest median income?
| SELECT `Sales Channel` FROM ( SELECT T1.`Sales Channel` FROM `Sales Orders` AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StoreID = T1._StoreID ORDER BY T2.`Median Income` DESC LIMIT 3 ) GROUP BY `Sales Channel` ORDER BY COUNT(`Sales Channel`) DESC LIMIT 1; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- List the 5 sales teams that have made sales with the highest net profits.
| SELECT T2.`Sales Team` FROM `Sales Orders` AS T1 INNER JOIN `Sales Team` AS T2 ON T2.SalesTeamID = T1._SalesTeamID ORDER BY REPLACE(T1.`Unit Price`, ',', '') - REPLACE(T1.`Unit Cost`, ',', '') DESC LIMIT 5; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- What is the highest discount applied by the store located in a city of the state of Colorado whose land area is 111039036.
| SELECT MAX(T1.`Discount Applied`) FROM `Sales Orders` AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StoreID = T1._StoreID WHERE T2.State = 'Colorado' AND T2.`Land Area` = 111039036; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- How many different time zones are there in the Northeast region?
| SELECT COUNT(DISTINCT T2.`Time Zone`) FROM Regions AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StateCode = T1.StateCode WHERE T1.Region = 'Northeast'; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- What type of store is most popular in the South?
| SELECT DISTINCT CASE WHEN MAX(T2.Population) THEN T2.Type END FROM Regions AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StateCode = T1.StateCode; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- To which region does the sales team that has used the WARE-MKL1006 warehouse the most times for its shipments belong?
| SELECT T2.Region FROM `Sales Orders` AS T1 INNER JOIN `Sales Team` AS T2 ON T2.SalesTeamID = T1._SalesTeamID WHERE T1.WarehouseCode = 'WARE-MKL1006' GROUP BY T2.Region ORDER BY COUNT(T1.OrderNumber) DESC LIMIT 1; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- In which city is the store with the highest sales order unit price located?
| SELECT T2.`City Name` FROM `Sales Orders` AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StoreID = T1._StoreID WHERE REPLACE(T1.`Unit Price`, ',', '') = ( SELECT REPLACE(T1.`Unit Price`, ',', '') FROM `Sales Orders` AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StoreID = T1._StoreID ORDER BY REPLACE(T1.`Unit Price`, ',', '') DESC LIMIT 1 ) ORDER BY REPLACE(T1.`Unit Price`, ',', '') DESC LIMIT 1; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- How many online purchases did Ole Group make in May 2019?
| SELECT SUM(CASE WHEN T1.`Sales Channel` = 'Online' AND T2.`Customer Names` = 'Ole Group' AND T1.OrderDate LIKE '5/%/19' THEN 1 ELSE 0 END) FROM `Sales Orders` AS T1 INNER JOIN Customers AS T2 ON T2.CustomerID = T1._CustomerID; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- How many stores with less need for products, and purchased through a distributor, are located in Washtenaw County?
| SELECT SUM(CASE WHEN T1.`Order Quantity` = 1 AND T1.`Sales Channel` = 'Distributor' AND T2.County = 'Washtenaw County' THEN 1 ELSE 0 END) FROM `Sales Orders` AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StoreID = T1._StoreID; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- What is the least purchased product by stores in the city of Santa Clarita?
| SELECT T1.`Product Name` FROM Products AS T1 INNER JOIN `Sales Orders` AS T2 ON T2._ProductID = T1.ProductID INNER JOIN `Store Locations` AS T3 ON T3.StoreID = T2._StoreID WHERE T3.`City Name` = 'Santa Clarita' GROUP BY T1.`Product Name` ORDER BY COUNT(T1.`Product Name`) ASC LIMIT 1; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- At what Latitude and Longitude is the store that has used the WARE-PUJ1005 warehouse the fewest times?
| SELECT T2.Latitude, T2.Longitude FROM `Sales Orders` AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StoreID = T1._StoreID WHERE T1.WarehouseCode = 'WARE-PUJ1005' GROUP BY T2.StoreID ORDER BY COUNT(T1.WarehouseCode) ASC LIMIT 1; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- What percentage of sell orders on 04/04/2020 were for the state of New York?
| SELECT CAST(SUM(CASE WHEN T2.State = 'New York' THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(T1.OrderNumber) FROM `Sales Orders` AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StoreID = T1._StoreID WHERE T1.OrderDate = '4/4/20'; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- What is the average land area of the cities in which stores that purchased products for a unit price of 998.30 are located?
| SELECT AVG(T2.`Land Area`) FROM `Sales Orders` AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StoreID = T1._StoreID WHERE T1.`Unit Price` = '998.30'; |
-- Database schema
| Customers : CustomerID [ INTEGER ] primary_key , Customer Names [ TEXT ] | Products : ProductID [ INTEGER ] primary_key , Product Name [ TEXT ] | Regions : StateCode [ TEXT ] primary_key , State [ TEXT ] , Region [ TEXT ] | Sales Team : SalesTeamID [ INTEGER ] primary_key , Sales Team [ TEXT ] , Region [ TEXT ] | Store Locations : StoreID [ INTEGER ] primary_key , City Name [ TEXT ] , County [ TEXT ] , StateCode [ TEXT ] Store Locations.StateCode = Regions.StateCode , State [ TEXT ] , Type [ TEXT ] , Latitude [ REAL ] , Longitude [ REAL ] , AreaCode [ INTEGER ] , Population [ INTEGER ] , Household Income [ INTEGER ] , Median Income [ INTEGER ] , Land Area [ INTEGER ] , Water Area [ INTEGER ] , Time Zone [ TEXT ] | Sales Orders : OrderNumber [ TEXT ] primary_key , Sales Channel [ TEXT ] , WarehouseCode [ TEXT ] , ProcuredDate [ TEXT ] , OrderDate [ TEXT ] , ShipDate [ TEXT ] , DeliveryDate [ TEXT ] , CurrencyCode [ TEXT ] , _SalesTeamID [ INTEGER ] Sales Orders._SalesTeamID = Sales Team.SalesTeamID , _CustomerID [ INTEGER ] Sales Orders._CustomerID = Customers.CustomerID , _StoreID [ INTEGER ] Sales Orders._StoreID = Store Locations.StoreID , _ProductID [ INTEGER ] Sales Orders._ProductID = Products.ProductID , Order Quantity [ INTEGER ] , Discount Applied [ REAL ] , Unit Price [ TEXT ] , Unit Cost [ TEXT ] |
-- -- What is the average household income in cities in the state of New Hampshire where there are stores of the type city?
| SELECT AVG(T2.`Household Income`) FROM Regions AS T1 INNER JOIN `Store Locations` AS T2 ON T2.StateCode = T1.StateCode WHERE T2.State = 'New Hampshire' AND T2.Type = 'City'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.