I want sum total of oiltype
where fullname = gift and
FDate = '01-10-2023' and vehicalType = 'car'
Also sum total of oiltype
where fullname = 'gift' and
FDate = '01-10-2023' and vehicalType = 'motorcycle'
In single query.
I’m write this code but not work.
Select vehicalType, sum(total) as total ,fullname, FDate
from paking_histories
where FDate = '01-10-2023' and oiltype ='oil' and Fullname ='gift';
Results needed.
Car motorcycle date
Total total 01-10-2023
>Solution :
You can use the conditional aggregation :
select sum(case when vehicalType = 'car' then total else 0 end) as car,
sum(case when vehicalType = 'motorcycle' then total else 0 end) as motorcycle,
FDate
from paking_histories
where FDate = '2023-10-01' and oiltype ='oil' and Fullname ='gift'