Hope someone can help me with this one, is really staring myself blind on it.
I have a table which stores products that users have selected and in that table I store ordertime and pickedup and pickuptime. So structur is index(PRIMARY INT), ordernr(INT), ordertime(TIMESTAMP), productid(INT), pickedup(TINYINT), pickeduptime(TIMESTAMP).
Now I would love to get a result set for a graph, that says, Date, count of ordered products and count of products pickedup on, group and ordered by dates. My problem now is that I get almost right numbers, but the pickedup are counted into the ordered and I cant seem to get my head around this.
SELECT (case when pickedup = '1' then DATE(order_detail.pickeduptime) else DATE(order_detail.ordertime) end) AS x,COUNT(productid) AS y,SUM(case when pickedup = '1' then 1 else 0 end) AS z FROM order_detail WHERE productid = '127' AND YEAR(`ordertime`) = YEAR(NOW()) GROUP BY x ORDER BY x asc
Any help would be much appriciated. :-)
UPDATED:
1 index int(11) AUTO_INCREMENT Primary
2 ordernr int(11)
3 productid int(11)
4 price int(11)
5 ordertime timestamp CURRENT_TIMESTAMP
6 pickedup tinyint(4) 0
7 pickeduptime timestamp 0000-00-00 00:00:00
How table looks.