Questions: What is the forecasted sales for 2022 for Department ABC?

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where year(date) = 2022 and [department name] = 'abc'


Questions: What is the forecasted sales for 2022 for Location AYZ?

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where year(date) = 2022 and location = 'ayz'


Questions: What is the forecasted sales for 2022 for Account name Depreciation?

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where year(date) = 2022 and [Account name] like '%depreciation%'


Questions: What is the forecasted sales for 2022 for Geography AY?

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where year(date) = 2022 and gepgraphy = 'ay'


Questions: Entity Alpha has how many unique departments?

SQL Query: select count( distinct (department name)) from forecasted_table where enity = 'Alpha'


Questions: Entity Alpha has how many unique locations?

SQL Query: select count( distinct (location)) from forecasted_table where enity = 'Alpha'


Questions: Entity Alpha has how many unique geographies?

SQL Query: select count( distinct (geography)) from forecasted_table where enity = 'Alpha'


Questions: Entity Alpha has how many unique accounts?

SQL Query: select count( distinct (account name)) from forecasted_table where enity = 'Alpha'


Questions: find unique departments?

SQL Query: select count( distinct (department name)) from forecasted_table


Questions: how many unique locations are there?

SQL Query: select count( distinct (location)) from forecasted_table


Questions: find unique accounts?

SQL Query: select count( distinct (account name)) from forecasted_table


Questions: find unique entities?

SQL Query: select count( distinct (entity)) from forecasted_table


Questions: What is the total forecasted sales for 2022 for location L02?

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 and [location] = 'L02'


Questions: What is the total forecasted sales for 2022 for print?

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 and [account name] like '%print%'


Questions: What is the quarter 3 sales for Location L03?

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where quarter = 3 and [location] = 'L03'


Questions: What is the quarter 3 sales for Entity Alpha?

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where quarter = 3 and [entity] = 'alpha'


Questions: What is the quarter 3 sales for Department DL08?

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where quarter = 3 and [department name] = 'DL08'


Questions: What is the quarter 3 sales for Sales discount?

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where quarter = 3 and [account name] like '%sales discount%'


Questions: How many years of forecasted data do we have in the table?

SQL Query: select distinct (year(date)) from forecasted_table


Questions: For Entity Alpha, what is the latest forecast available?

SQL Query: select max(year(date)), max(month(date)) from forecasted_table where [entity] = 'Alpha'


Questions: what is the latest forecast available for location L76?

SQL Query: select max(year(date)), max(month(date)) from forecasted_table where [location] = 'L76'


Questions: What is the latest forecast available for Geography GL877?

SQL Query: select max(year(date)), max(month(date)) from forecasted_table where [geography] = 'GL877'


Questions: What is the average forecasted sales per entity?

SQL Query: select entity, avg(isnull(sales_forecast,0)) from forecasted_table group by entity


Questions: What is the average forecasted sales per department?

SQL Query: select  [department name], avg(isnull(sales_forecast,0)) from forecasted_table group by [department name]


Questions: What is the average forecasted sales per location?

SQL Query: select location, avg(isnull(sales_forecast,0)) from forecasted_table group by location


Questions: What is the average forecasted sales per account?

SQL Query: select  [account name], avg(isnull(sales_forecast,0)) from forecasted_table group by [account name]


Questions: What is the average forecasted sales per geography?

SQL Query: select geography, avg(isnull(sales_forecast,0)) from forecasted_table group by geography


Questions: Find the total sales for 2023 for accounts that contain "merchandise sales"

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where year(date) = 2023 and [account name] like '%merchandise sales%'


Questions: Find the total sales for 2023 for department name that contain "DL"

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where year(date) = 2023 and [department name] like '%DL%'


Questions: Find the total sales for 2023 for accounts that start with "merchandise sales"

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where year(date) = 2023 and [account name] like 'merchandise sales%'


Questions: Find the total sales for 2023 for department name that start with "DP"

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where year(date) = 2023 and [account name] like 'DP%'


Questions: Find the unique departments that contain "DP"

SQL Query: select  distinct [department name] from forecasted_table where [department name] like '%dp%'


Questions: Find the unique accounts that contain "hr"

SQL Query: select  distinct [account name] from forecasted_table where [account name] like '%hr%'


Questions: find the total sales for year 2023 for locations- ABC, AHC, and JIE

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where year(date) = 2023 and [location] in ('ABC', 'AHC' , 'JIE')


Questions: find the total sales for year 2023 for department name- DL001,DL002, AND DL003

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where year(date) = 2023 and [department name] in ('DL001', 'DL002', 'DL003')


Questions: find the total sales for year 2023 for geography- GL001,GL002, AND GL003

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where year(date) = 2023 and [geography] in ('GL001', 'GL002', 'GL003')


Questions: find the total sales for year 2023 for entity- Alpha and beta

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where year(date) = 2023 and [entity] in ('alpha', 'beta')


Questions: Find accounts with sales forecast between 20000-30000 in 2023?

SQL Query: select [account name], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2023 group by [account name] having sum(isnull(sales_forecast,0)) >=20000 and sum(isnull(sales_forecast,0)) < 30000


Questions: Find departments with sales forecast between 50000-80000 in 2023?

SQL Query: select [department name], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2023 group by [department name] having sum(isnull(sales_forecast,0)) >=50000 and sum(isnull(sales_forecast,0)) < 80000


Questions: What is the department number for Finance

SQL Query: select distinct [department number] from forecasted_table where [department name] like '%Finance%'


Questions: What is the account number for Overtime - (Hrly) - Corporate account

SQL Query: select distinct [account number] from forecasted_table where [account name] like '%Overtime - (Hrly) - Corporate%'


Questions: Fine total sales in 2023 for account 401?

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2023 where [account number] = 401


Questions: What is the total sales in 2022 for department number FD32

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2023 where [department number] = 'FD32'


Questions: How much is forecasted department spend on Brand Marketing in 2023

SQL Query: select sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2023 and [department name] like '%Brand Marketing%'


Questions: What is the forecasted location wise sales for Alpha in year 2022?

SQL Query: select  location ,sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 and entity = 'alpha' group by location


Questions: Find forecasted sales in 2022 by  department for location AL001?

SQL Query: select  [department name], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 and location = 'al001' group by [department name]


Questions: find forecasted 2022 account wise sales for department depreciation?

SQL Query: select  [account name] ,sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 and [department name] = 'depreciation' group by [account name]


Questions: find the forecasted sales by  Locations for year 2022?

SQL Query: select  location ,sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by location


Questions: what is forecasted sales across different departments for year 2022?

SQL Query: select  [department name] ,sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by [department name]


Questions: find forecasted sales by geographies for year 2022?

SQL Query: select  geography ,sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by geography


Questions: what is the forecasted sales across different accounts for year 2022?

SQL Query: select  [account name] ,sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by [account name]


Questions: find forecasted sales by entities for year 2022?

SQL Query: select  entity ,sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by entity


Questions: find the top 2 location in Alpha projected to have highest sales_forecast for 2022

SQL Query: select top 2 [location], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by location order by sales_forecast desc


Questions: find the top 5 locations in Alpha projected to have highest sales_forecast for 2022

SQL Query: select top 5 [location], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by location order by sales_forecast desc


Questions: find the top 3 geography in Alpha projected to have highest sales_forecast for 2022

SQL Query: select top 3 [geography], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by geography order by sales_forecast desc


Questions: find the top 10 departments in Alpha projected to have highest sales for 2022

SQL Query: select top 10 [department name], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022  group by [department name]  order by sales_forecast desc


Questions: Which Department has the lowest sales forecast in the year 2022?

SQL Query: select top 1 [department name], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by [department name] order by sales_forecast asc


Questions: Which account has lowest sales in the year 2022?

SQL Query: select top 1 [account name], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 order by sales_forecast asc


Questions: Which location has lowest sales in the year 2022?

SQL Query: select top 1 [location], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by location order by sales_forecast asc


Questions: Which geography has lowest sales in the year 2022?

SQL Query: select top 1 [geography], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by geography order by sales_forecast asc


Questions: Which entity has lowest sales in the year 2022?

SQL Query: select top 1 [entity], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by entity order by sales_forecast asc


Questions: Which Department has highest sales in the year 2022?

SQL Query: select top  1 [department name], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by [department name] order by sales_forecast desc


Questions: Which Entity has the highest forecasted sales for the current year?

SQL Query: select top 1 entity, sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = year(getdate()) group by entity order by sales_forecast desc


Questions: Which location has the highest forecasted sales for the current year?

SQL Query: select top 1 location, sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = year(getdate()) group by location order by sales_forecast desc


Questions: Which account has the highest forecasted sales for the current year?

SQL Query: select top 1 [account name], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = year(getdate()) group by [account name] order by sales_forecast desc


Questions: Which geography has the highest forecasted sales for the current year?

SQL Query: select top 1 geography, sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = year(getdate()) group by geography order by sales_forecast desc


Questions: find the breakdown of forecasted sales for 2022 for each Geography by Department?

SQL Query: select  geography, [department name], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by geography, [department name]


Questions: find the breakdown of forecasted sales for 2022 for each account by Department?

SQL Query: select  [account name], [department name], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by [account name], [department name]


Questions: find the breakdown of forecasted sales for 2022 for each Geography by location?

SQL Query: select  geography, [location], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by geography, [location]


Questions: What are the forecasted sales figures for each account over year 2022 sort by descending order?

SQL Query: select  [account name], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by [account name] order by sales_forecast desc


Questions: What are the forecasted sales figures for each account over year 2022 sort by ascending order?

SQL Query: select  [account name], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by [account name] order by sales_forecast asc


Questions: What are the forecasted sales figures for each department over year 2022 sort by descending order?

SQL Query: select  [department name], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by [department name] order by sales_forecast desc


Questions: What are the forecasted sales figures for each department over year 2022 sort by ascending order?

SQL Query: select  [department name], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by [department name] order by sales_forecast asc


Questions: What are the forecasted sales figures for each location over year 2022 sort by ascending order?

SQL Query: select  [location], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by [location] order by sales_forecast asc


Questions: What are the forecasted sales figures for each location over year 2022 sort by descending order?


Questions: What is the average forecasted sales for year 2022  in each location?

SQL Query: select location, avg(isnull(sales_forecast,0)) from forecasted_table where year(Date)  = 2022 group by location


Questions: What is the average forecasted sales for year 2022  in each department?

SQL Query: select [department name], avg(isnull(sales_forecast,0)) from forecasted_table where year(Date)  = 2022 group by [department name]


Questions: What is the average forecasted sales for year 2022  in each entity?

SQL Query: select entity, avg(isnull(sales_forecast,0)) from forecasted_table where year(Date)  = 2022 group by entity


Questions: What is the average forecasted sales for year 2022  in each account?

SQL Query: select [account name], avg(isnull(sales_forecast,0)) from forecasted_table where year(Date)  = 2022 group by [account name]


Questions: What is the average forecasted sales for year 2022  in each geography?

SQL Query: select geography, avg(isnull(sales_forecast,0)) from forecasted_table where year(Date)  = 2022 group by geography


Questions: What is the average forecasted sales  in each location?

SQL Query: select location, avg(isnull(sales_forecast,0)) from forecasted_table group by location


Questions: What is the average forecasted sales  in each department?

SQL Query: select [department name], avg(isnull(sales_forecast,0)) from forecasted_table group by [department name]


Questions: What is the average forecasted sales  in each entity?

SQL Query: select entity, avg(isnull(sales_forecast,0)) from forecasted_table group by entity


Questions: Account wise projected sales for Wholesale department in 2022?

SQL Query: select [account name], sum(isnull(sales_forecast,0)) from forecasted_table where [department name] = 'wholesale' and year(Date) = 2022 group by [account name]


Questions: Location wise projected sales for Sales discount account in 2022?

SQL Query: select location, sum(isnull(sales_forecast,0)) from forecasted_table where [account name] = 'sales discount' and year(Date) = 2022 group by location


Questions: Geography wise projected sales for ABC entity in 2022?

SQL Query: select geography, sum(isnull(sales_forecast,0)) from forecasted_table where [entity] = 'abc' and year(Date) = 2022 group by geography


Questions: Entity wise projected sales for Wholesale department in 2022?

SQL Query: select entity, sum(isnull(sales_forecast,0)) from forecasted_table where [entity] = 'abc' and year(Date) = 2022 group by entity


Questions: What is the average forecasted sales  in each account?

SQL Query: select [account name], avg(isnull(sales_forecast,0)) from forecasted_table group by [account name]


Questions: What is the average forecasted sales  in each geography?

SQL Query: select geography, avg(isnull(sales_forecast,0)) from forecasted_table group by geography


Questions: Departments projected to have yearly sales below 150,000 are termed as "Low expense departments". How many such departments do we have in 2022?

SQL Query: select count(*) from (select [department number], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by [department number] having sum(isnull(sales_forecast,0)) < 150000)


Questions: Accounts projected to have yearly sales below 50,000 are termed as "Low activity accounts". How many such accounts do we have in 2022?

SQL Query: select count(*) from (select [account number], sum(isnull(sales_forecast,0)) from forecasted_table where year(Date) = 2022 group by [account number] having sum(isnull(sales_forecast,0)) < 50000)


Questions: Location wise projected sales for Wholesale department in 2022?

SQL Query: select location, sum(isnull(sales_forecast,0)) from forecasted_table where [department name] like '%wholesale%' and year(Date) = 2022 group by location


Questions: find average sales for each entity, geography, department and location for the year 2022?

SQL Query: select entity, geography , [department name], location, sum(isnull(sales_forecast,0))/count(distinct [department number]) from forecasted_table where year(date) = 2022 group by entity, geography ,[department name], location


Questions: find average sales per department for each entity, geography and location?

SQL Query: select entity, geography , location, sum(isnull(sales_forecast,0))/count(distinct [department number]) from forecasted_table group by entity, geography , location


Questions: For product cost account, what is the forecasted sales growth in the month of 5 year 2022 compared to previous month?

SQL Query:
SELECT
   [account name],year(Date),month(date),
    case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY  [account name] ORDER BY year(Date),month(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),month(date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY  [account name] ORDER BY year(Date),month(date)))*100),2)  end as sales_forecast_growth
FROM
    forecasted_table
where  [account name] like '%product cost%' and year(date) = 2022 and month(date) = 5
    group by   [account name] ,year(Date),month(date)
ORDER BY
  [account name] ,year(Date),month(date)


Questions: For finance department, what is the forecasted sales growth in the month of 7 year 2022 compared to previous month?

SQL Query:
SELECT
   [department name],year(Date),month(date),
    case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY  [department name] ORDER BY year(Date),month(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),month(date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY  [department name] ORDER BY year(Date),month(date)))*100),2)  end as sales_forecast_growth
FROM
    forecasted_table
where  [department name] = 'finance' and year(date) = 2022 and month(date) = 7
    group by   [department name] ,year(Date),month(date)
ORDER BY
  [department name] ,year(Date),month(date)


Questions: What is the forecasted sales growth for entity ABC in the month of 6 year 2022 compared to previous month?

SQL Query:
SELECT
   [entity],year(Date),month(date),
    case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY  [entity] ORDER BY year(Date),month(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),month(date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY  [entity] ORDER BY year(Date),month(date)))*100),2)  end as sales_forecast_growth
FROM
    forecasted_table
where  [entity] = 'ABC' and year(date) = 2022 and month(date) = 6
    group by   [entity] ,year(Date),month(date)
ORDER BY
  [entity] ,year(Date),month(date)


Questions: What is the forecasted sales growth for Location AB23 in the month of 5 year 2022 compared to previous month?

SQL Query:
SELECT
   [location],year(Date),month(date),
    case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY  [location] ORDER BY year(Date),month(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),month(date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY  [location] ORDER BY year(Date),month(date)))*100),2)  end as sales_forecast_growth
FROM
    forecasted_table
where  [location] = 'AB23' and year(date) = 2022 and month(date) = 5
    group by   [location] ,year(Date),month(date)
ORDER BY
  [location] ,year(Date),month(date)


Questions: For customer service department , what is the forecasted sales growth in the month of 2 year 2022 compared to previous month?

SQL Query:
SELECT
   [department name],year(Date),month(date),
    case when LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY  [department name] ORDER BY year(Date),month(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),month(date))) /LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY  [department name] ORDER BY year(Date),month(date)))*100),2)  end as sales_forecast_growth
FROM
    forecasted_table
where  [department name] = 'customer service' and year(date) = 2022 and month(date) = 2
    group by   [department name] ,year(Date),month(date)
ORDER BY
  [department name] ,year(Date),month(date)


Questions: What is the difference in forecasted sales for HR Department for year 2023 Vs 2022

SQL Query:
SELECT
    [department name],year(Date),
   sum(isnull(sales_forecast,0)) - LAG(sum(isnull(sales_forecast,0))) OVER (PARTITION BY [department name] ORDER BY year(Date)) AS sales_forecastDifference
FROM
    forecasted_table
where [department name] like '%hr%' and year(date) = 2023
    group by  [department name],year(Date)
ORDER BY
   [department name],year(Date)


Questions: What is the difference in forecasted sales for sales rebate account for year 2022 and 2023

SQL Query:
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)


Questions: What is the difference in forecasted sales for entity ABC for year 2022 and 2023

SQL Query:
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)


Questions: find the percentage change in forecasted sales compared to the previous year for each Entity?

SQL Query:
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)


Questions: For each department, find the percentage change in forecasted sales compared to the previous year?

SQL Query:
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)


Questions: For each location, find the percentage change in forecasted sales compared to the previous year?

SQL Query:
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)


Questions: For each geography, find the percentage change in forecasted sales compared to the previous year?

SQL Query:
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)


Questions: Which Department is expected to see the most significant growth in the 2023?

SQL Query:
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


Questions: Which Account is expected to see the most significant growth in sales in the 2023?

SQL Query:
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


Questions: Which Entity is expected to see the most significant growth in sales in the 2023?

SQL Query:
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


Questions: Which Location is expected to see the most significant growth in sales in the 2023?

SQL Query:
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


Questions: How many departments are projected to have sales greater than 1 million in 2022?

SQL Query: 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)


Questions: How many locations are projected to have sales greater than 1 million in 2022?

SQL Query: 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)


Questions: How many accounts are projected to have sales greater than 1 million in 2022?

SQL Query: 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)


Questions: Top 5 accounts in 2023 having highest growth rate of forecasted sales?

SQL Query:
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


Questions: Top 5 departments in 2023 having highest growth rate of forecasted sales?

SQL Query:
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


Questions: Top 5 location in 2023 having highest growth rate of forecasted sales?

SQL Query:
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


Questions: Top 5 geography in 2023 having highest growth rate of forecasted sales?

SQL Query:
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


Questions: Top 5 entity in 2023 having highest growth rate of forecasted sales?

SQL Query:
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


Questions: Which Department is expected to see the least significant growth in the 2023?

SQL Query:
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


Questions: Which Account is expected to see the least significant growth in sales in the 2023?

SQL Query:
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


Questions: Which Entity is expected to see the least significant growth in sales in the 2023?

SQL Query:
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