Hi everyone,
After "Decade" from beginning, I have to ask this question:
how to show up zero volume in group by query w/o losing performance.
I have 2 tables like this:
(Raw data) Table1 = {CID, Name, ItemID, BDate, Quantity, Price}
(List Client) Table2 = {CustID, CustName}
ok, my current SQL to show up 0 quantity Client below:
if I use this 2nd SQL below, all 0-Volume-Client will be disappeared
how to show those Client without using 1st SQL or losing performance ?
Edit:
I have idea using Subquery like this:
After "Decade" from beginning, I have to ask this question:
how to show up zero volume in group by query w/o losing performance.
I have 2 tables like this:
(Raw data) Table1 = {CID, Name, ItemID, BDate, Quantity, Price}
(List Client) Table2 = {CustID, CustName}
ok, my current SQL to show up 0 quantity Client below:
Code:
SELECT CustID, CustName, iif(Month(BDate)=11,Month(BDate),11) as BMonth, Sum(iif(Month(BDate)=11,Quatity,0)) as Total-MTD FROM Table2 LEFT JOINT Table1 ON Table2.CustID = Table1.CID WHERE iif(Month(BDate)=11,Month(BDate),11) = 11 GROUP BY CustID, CustName, Month(BDate) ORDER BY CustID, Month(BDate);
Code:
SELECT CustID, CustName, Month(BDate) as BMonth, Sum(Quatity) as Total-MTD FROM Table2 LEFT JOINT Table1 ON Table2.CustID = Table1.CID WHERE Month(BDate) = 11 GROUP BY CustID, CustName, Month(BDate) ORDER BY CustID, Month(BDate);
Edit:
I have idea using Subquery like this:
Code:
SELECT CustID, CustName, Month(BDate) as BMonth, Sum(Quatity) as Total-MTD FROM Table2 LEFT JOINT Table1 ON Table2.CustID = Table1.CID WHERE Month(BDate) = 11 GROUP BY CustID, CustName, Month(BDate) ORDER BY CustID, Month(BDate) UNION ALL SELECT CustID, CustName, 11 as BMonth, 0 as Total-MTD FROM Table2 LEFT JOINT Table1 ON Table2.CustID = Table1.CID WHERE NOT EXIST (SELECT CustID, CustName, Month(BDate) as BMonth, Sum(Quatity) as Total-MTD FROM Table2 LEFT JOINT Table1 ON Table2.CustID = Table1.CID WHERE Month(BDate) = 11 GROUP BY CustID, CustName, Month(BDate) ORDER BY CustID, Month(BDate));
Comment