Hi,
Need help with following query
this query needs to count new/used totals, grouped by date - however the query above counts
all items under usedtotal - unless there are no used items, in which case the correct total is shown under newtotal
hope this makes sense - let me if not
Need help with following query
Code:
SELECT
IF((TS.statusid=2), (count(TA.actionid)), 0) AS usetotal,
IF((TS.statusid=1 OR TS.statusid =3), (count(TA.actionid)), 0) AS newtotal,
R.date
FROM event AS TD
LEFT JOIN action AS TA ON TA.eventid = TD.eventid
LEFT JOIN eventstocklink AS TS ON TS.eventstocklinkid = TA.eventstocklinkid
LEFT JOIN stockstate AS TST ON TST.stateid = TS.statusid
LEFT JOIN response AS R ON R.actionid = TA.actionid
LEFT JOIN saletypelink AS STL ON STL.saletypelinkid = TD.saletypeid
LEFT JOIN saletype AS ST ON ST.saletypeid = STL.saletypeid
WHERE R.reasonid = 'Handover' AND R.date BETWEEN '20090921' AND '20090927' AND TD.siteid = 1
GROUP BY date(r.date)
ORDER BY date(r.date)
this query needs to count new/used totals, grouped by date - however the query above counts
all items under usedtotal - unless there are no used items, in which case the correct total is shown under newtotal
hope this makes sense - let me if not