Hi,
I need help with syntax but I dunno if what I want is possible. I need to retrieve the # of items sold and then broken down into; year to date, period to date , and total items sold. Can this be done with 1 query?
I need help with syntax but I dunno if what I want is possible. I need to retrieve the # of items sold and then broken down into; year to date, period to date , and total items sold. Can this be done with 1 query?
Code:
SELECT count(id) as 'Total Items Sold',
if((date_format(visit_date,'%Y') = date_format(current_date,'%Y')), count(id), 0) AS `Year To Date Items Sold`,
if((date_format(visit_date,'%Y-%m-%d') BETWEEN date_format('2007-05-06','%Y-%m-%d') AND date_format('2007-11-26','%Y-%m-%d')), 0, count(id)) AS `Period To Date Items Sold`
FROM table
GROUP BY id;