Hi,
Need [TOTAL] to add derived fields as per below, but cant get it to work - any ideas welcome
Need [TOTAL] to add derived fields as per below, but cant get it to work - any ideas welcome
Code:
SELECT IF(ISNULL(newcount), 0, newcount) AS newcount,
IF(ISNULL(usedcount), 0, usedcount) AS usedcount,
(newcount + usedcount) AS TOTAL
FROM users
LEFT JOIN (SELECT count(action.actionid) AS newcount, action.userid FROM action INNER JOIN deal ON deal.actionid = action.actionid INNER JOIN eventstocklink ON eventstocklink.eventstocklinkid = action.eventstocklinkid WHERE (eventstocklink.statusid = 1 OR eventstocklink.statusid = 3 AND action.typeid = 2) AND date(action.actiondate) BETWEEN '20090801' AND '20090831' GROUP BY action.userid) AS newcount ON newcount.userid = users.userid
LEFT JOIN (SELECT count(action.actionid) AS usedcount, action.userid FROM action INNER JOIN deal ON deal.actionid = action.actionid INNER JOIN eventstocklink ON eventstocklink.eventstocklinkid = action.eventstocklinkid WHERE (eventstocklink.statusid = 2 AND action.typeid = 2) AND date(action.actiondate) BETWEEN '20090801' AND '20090831' GROUP BY action.userid) AS usedcount ON usedcount.userid = users.userid