I have sales table data as shown below
I want it to display group wise sales according to Date. Sales table contains data for different groups but my query shows only two rows.
The SQL Query:
select
i.gName,
sum(Quantity) as '180ml',
isnull((select sum(Quantity)
from saleslog
where BillDate='12-10-2010'
and pSize=375 and pGroup=i.gCode),0) as '375ml',
isnull((select sum(Quantity)
from saleslog
where BillDate='12-10-2010'
and pSize=500 and pGroup=i.gCode),0) as '500ml',
isnull((select sum(Quantity)
from saleslog
where BillDate='12-10-2010'
and pSize=750 and pGroup=i.gCode),0) as '750ml',
isnull((select sum(Quantity)
from saleslog
where BillDate='12-10-2010'
and pSize=1000 and pGroup=i.gCode),0) as '1000ml',
isnull((select sum(Quantity)
from saleslog
where BillDate='12-10-2010'
and pSize=2000 and pGroup=i.gCode),0) as '2000ml'
from saleslog as s
inner join ItemGroup as i on s.pGroup=i.gCode
where BillDate='12-10-2010'
and i.gCode=pGroup
and pSize=180
group by i.gCode,i.gName
Output of above query
WHISKY 5 2 0 0 0 0
RUM 82 0 0 45 0 0
It is showing these results, but I expected it to list all product groups as follows:
Product Group Table :
1 BRANDY 1
2 WHISKY 2
3 RUM 3
4 GIN 4
5 VODKA 5
6 BEER 8
7 WINE 6
8 LIQUOR 7
9 SCOTCH WHY 9
10 LUBRICANT 15
11 UNTAXABLE 16
12 O/S LIQUOR 10
13 RTD 11
14 275 ML 12
What's wrong with my query?