Write the query in SQL:
Sample output:
Table:
Hi,
Below is the query for the problem.
Assumptions -
1. Assuming table name as Test.
select cust as customer,prod as product,month,qty as
current,LAG(qty, 1,null) OVER (PARTITION BY cust,prod ORDER BY
month) as before_avg,
LEAD(qty, 1,null) OVER (PARTITION BY cust,prod ORDER BY month) as
after_avg
from(
select cust,prod,month,avg(quant) as qty from test group by
cust,prod,month order by prod,month) k
order by prod,month
2. Created sample data as per the image given in question. Here is the output of the query-
Write the query in SQL: Sample output: Table: For customer and product, show the average sales before and after each month (e.g., for February, show average sales of January and March. For "bef...