nickname2485
Aug 25, 2023Copper Contributor
Write SQL query
Hello,
I could solve this:
For each customer/date show daily profit/loss and compare it with previous day same customers profit/loss.
I tried this but I am not sure if it is ok:
select fullname,
profitloss,
date,
lag(profitloss) over (partition by DailyProfitLoss.PersonId order by DailyProfitLoss.Date) - DailyProfitLoss.ProfitLoss as diff_to_prev,
lead(profitloss) over (partition by DailyProfitLoss.PersonId order by DailyProfitLoss.Date) - DailyProfitLoss.ProfitLoss as diff_to_next
from Customers, DailyProfitLoss WHERE Customers.PersonID=DailyProfitLoss.personid;