Questions
stringlengths
21
143
SQL Query
stringlengths
50
718
What is the difference in forecasted sales for sales rebate account for year 2022 and 2023
SELECT [account name],year(Date), sum(isnull(sales_forecast,0)) - LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [account name] ORDER BY year(Date)) AS sales_forecastDifference FROM forecasted_table where [account name] like '%sales rebate%' and year(date) = 2023 group by [account name],year(Date) ORDER BY [account name],year(Date)
What is the difference in forecasted sales for entity ABC for year 2022 and 2023
SELECT [entity],year(Date), sum(isnull(sales_forecast,0)) - LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [entity] ORDER BY year(Date)) AS sales_forecastDifference FROM forecasted_table where [entity] = 'ABC' and year(date) = 2023 group by [entity],year(Date) ORDER BY [account name],year(Date)
find the percentage change in forecasted sales compared to the previous year for each Entity?
SELECT entity, year(Date), case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY entity ORDER BY year(Date)) = 0 then null else decimal(((sum(isnull(sales_forecast,0)) - LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY entity ORDER BY year(Date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY entity ORDER BY year(Date)))*100),2) end as sales_forecast_growth FROM forecasted_table group by entity, year(Date) ORDER BY entity, year(Date)
For each department, find the percentage change in forecasted sales compared to the previous year?
SELECT [department name],year(Date), case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [department name] ORDER BY year(Date)) = 0 then null else decimal(((sum(isnull(sales_forecast,0)) - LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [department name] ORDER BY year(Date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [department name] ORDER BY year(Date)))*100),2) end as sales_forecast_growth FROM forecasted_table group by [department name],year(Date) ORDER BY [department name],year(Date)
For each location, find the percentage change in forecasted sales compared to the previous year?
SELECT [location],year(Date), case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [location] ORDER BY year(Date)) = 0 then null else decimal(((sum(isnull(sales_forecast,0)) - LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [ location] ORDER BY year(Date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [location] ORDER BY year(Date)))*100),2) end as sales_forecast_growth FROM forecasted_table group by [location],year(Date) ORDER BY [location],year(Date)
For each geography, find the percentage change in forecasted sales compared to the previous year?
SELECT [geography],year(Date), case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [geography] ORDER BY year(Date)) = 0 then null else decimal(((sum(isnull(sales_forecast,0)) - LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [ geography] ORDER BY year(Date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [geography] ORDER BY year(Date)))*100),2) end as sales_forecast_growth FROM forecasted_table group by [geography],year(Date) ORDER BY [geography],year(Date)
Which Department is expected to see the most significant growth in the 2023?
SELECT top 1 [department name],year(Date), case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [department name] ORDER BY year(Date)) = 0 then null else decimal(((sum(isnull(sales_forecast,0)) - LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [department name] ORDER BY year(Date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [department name] ORDER BY year(Date)))*100),2) end as sales_forecast_growth FROM forecasted_table where year(date) = 2023 group by [department name],year(Date) ORDER BY sales_forecast_growth desc
Which Account is expected to see the most significant growth in sales in the 2023?
SELECT top 1 [account name],year(Date), case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [account name] ORDER BY year(Date)) = 0 then null else decimal(((sum(isnull(sales_forecast,0)) - LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [account name] ORDER BY year(Date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [account name] ORDER BY year(Date)))*100),2) end as sales_forecast_growth FROM forecasted_table where year(date) = 2023 group by [account name],year(Date) ORDER BY sales_forecast_growth desc
Which Entity is expected to see the most significant growth in sales in the 2023?
SELECT top 1 [entity],year(Date), case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [entity] ORDER BY year(Date)) = 0 then null else decimal(((sum(isnull(sales_forecast,0)) - LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [entity] ORDER BY year(Date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [entity] ORDER BY year(Date)))*100),2) end as sales_forecast_growth FROM forecasted_table where year(date) = 2023 group by [entity],year(Date) ORDER BY sales_forecast_growth desc
Which Location is expected to see the most significant growth in sales in the 2023?
SELECT top 1 [location],year(Date), case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [location] ORDER BY year(Date)) = 0 then null else decimal(((sum(isnull(sales_forecast,0)) - LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [location] ORDER BY year(Date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [location] ORDER BY year(Date)))*100),2) end as sales_forecast_growth FROM forecasted_table where year(date) = 2023 group by [location],year(Date) ORDER BY sales_forecast_growth desc
How many departments are projected to have sales greater than 1 million in 2022?
select count(*) from (select [department name], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by [department name] having sum(isnull(sales_forecast,0)) > 1000000)
How many locations are projected to have sales greater than 1 million in 2022?
select count(*) from (select [location], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by [location] having sum(isnull(sales_forecast,0)) > 1000000)
How many accounts are projected to have sales greater than 1 million in 2022?
select count(*) from (select [account name], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by [account name] having sum(isnull(sales_forecast,0)) > 1000000)
Top 5 accounts in 2023 having highest growth rate of forecasted sales?
SELECT top 5 [account name],year(Date), case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [account name] ORDER BY year(Date)) = 0 then null else decimal(((sum(isnull(sales_forecast,0)) - LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [account name] ORDER BY year(Date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [account name] ORDER BY year(Date)))*100),2) end as sales_forecast_growth FROM forecasted_table where year(date) = 2023 group by [account name],year(Date) ORDER BY sales_forecast_growth desc
Top 5 departments in 2023 having highest growth rate of forecasted sales?
SELECT top 5 [department name],year(Date), case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [department name] ORDER BY year(Date)) = 0 then null else decimal(((sum(isnull(sales_forecast,0)) - LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [department name] ORDER BY year(Date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [department name] ORDER BY year(Date)))*100),2) end as sales_forecast_growth FROM forecasted_table where year(date) = 2023 group by [department name],year(Date) ORDER BY sales_forecast_growth desc
Top 5 location in 2023 having highest growth rate of forecasted sales?
SELECT top 5 [location],year(Date), case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [location] ORDER BY year(Date)) = 0 then null else decimal(((sum(isnull(sales_forecast,0)) - LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [location] ORDER BY year(Date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [location] ORDER BY year(Date)))*100),2) end as sales_forecast_growth FROM forecasted_table where year(date) = 2023 group by [location],year(Date) ORDER BY sales_forecast_growth desc
Top 5 geography in 2023 having highest growth rate of forecasted sales?
SELECT top 5 [geography],year(Date), case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [geography] ORDER BY year(Date)) = 0 then null else decimal(((sum(isnull(sales_forecast,0)) - LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [geography] ORDER BY year(Date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [geography] ORDER BY year(Date)))*100),2) end as sales_forecast_growth FROM forecasted_table where year(date) = 2023 group by [geography],year(Date) ORDER BY sales_forecast_growth desc
Top 5 entity in 2023 having highest growth rate of forecasted sales?
SELECT top 5 [entity],year(Date), case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [entity] ORDER BY year(Date)) = 0 then null else decimal(((sum(isnull(sales_forecast,0)) - LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [entity] ORDER BY year(Date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [entity] ORDER BY year(Date)))*100),2) end as sales_forecast_growth FROM forecasted_table where year(date) = 2023 group by [entity],year(Date) ORDER BY sales_forecast_growth desc
Which Department is expected to see the least significant growth in the 2023?
SELECT top 1 [department name],year(Date), case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [department name] ORDER BY year(Date)) = 0 then null else decimal(((sum(isnull(sales_forecast,0)) - LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [department name] ORDER BY year(Date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [department name] ORDER BY year(Date)))*100),2) end as sales_forecast_growth FROM forecasted_table where year(date) = 2023 group by [department name],year(Date) ORDER BY sales_forecast_growth asc
Which Account is expected to see the least significant growth in sales in the 2023?
SELECT top 1 [account name],year(Date), case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [account name] ORDER BY year(Date)) = 0 then null else decimal(((sum(isnull(sales_forecast,0)) - LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [account name] ORDER BY year(Date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [account name] ORDER BY year(Date)))*100),2) end as sales_forecast_growth FROM forecasted_table where year(date) = 2023 group by [account name],year(Date) ORDER BY sales_forecast_growth asc
Which Entity is expected to see the least significant growth in sales in the 2023?
SELECT top 1 [entity],year(Date), case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [entity] ORDER BY year(Date)) = 0 then null else decimal(((sum(isnull(sales_forecast,0)) - LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [entity] ORDER BY year(Date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [entity] ORDER BY year(Date)))*100),2) end as sales_forecast_growth FROM forecasted_table where year(date) = 2023 group by [entity],year(Date) ORDER BY sales_forecast_growth asc