I have one sales table Order, This have previous month sales and this month sales , so I need 3 columns i.e. Name, this month total sales for selected name in where query and previous month sales.
Need in single query from same table
I have one sales table Order, This have previous month sales and this month sales , so I need 3 columns i.e. Name, this month total sales for selected name in where query and previous month sales.
Need in single query from same table
Something like this perhaps:
select customername
,sum(case
when salesdate>eomonth(current_timestamp,-1)
then 0
else salesprice
end
)
as lastmonth
,sum(case
when salesdate>eomonth(current_timestamp,-1)
then salesprice
else 0
end
)
as thismonth
from order
where salesdate>=dateadd(day,1,eomonth(current_timestamp,-2))
and salesdate<dateadd(day,1,eomonth(current_timestamp))
group by customername
;
It is working , now I have date table also , now what if tomorrow is Sunday then i want that instead of Sunday it should count Saturday as working days