Hi - have the following statement that almost displays what i need, except the fields countcurdealuse, countfwdealuse, countcurdealnew, countfwdealnew are not grouped on saletypelinkid - any ideas why?
Code:
SELECT STL.saletypelinkid,
SUM(case when TS.statusid=2 and 100*Year(dateadded)+Month(dateadded) = 100*Year(curDate()) +Month(curDate()) then 1 else 0 end) as countcurdealuse,
SUM(case when TS.statusid=2 and 100*Year(dateadded)+Month(dateadded) > 100*Year(curDate()) +Month(curDate()) then 1 else 0 end) as countfwdealuse,
SUM(case when TS.statusid=1 and 100*Year(dateadded)+Month(dateadded) = 100*Year(curDate()) +Month(curDate()) then 1 else 0 end) as countcurdealnew,
SUM(case when TS.statusid=1 and 100*Year(dateadded)+Month(dateadded) > 100*Year(curDate()) +Month(curDate()) then 1 else 0 end) as countfwdealnew
FROM saletypelink AS STL
LEFT JOIN deptlink AS TDP ON STL.deptlinkid = TDP.deptlinkid
LEFT JOIN event AS TD ON TD.deptlinkid = TDP.deptlinkid
LEFT JOIN eventstocklink AS TS ON TS.eventid = TD.eventid
GROUP BY STL.saletypelinkid
ORDER BY STL.saletypelinkid