There are 6 kind of ticket types. User will enter starting date and ending date. Then I have to show how many each type of tickets are on each days between those 2 date.
ticket table: id (int), type_id (int), created_at (date), and more fields
Input: date_begin, date_end
Output: rows > dates. columns > date, total_amount, and each types
My current query:
SELECT
DATE(ticket.created_date) as date,
SUM(IF(ticket.created_date, 1, 0)) as total,
SUM(IF(ticket.type_id is Null, 1, 0)) as total0,
SUM(IF(ticket.type_id = 1, 1, 0)) as total1,
SUM(IF(ticket.type_id = 2, 1, 0)) as total2,
SUM(IF(ticket.type_id = 3, 1, 0)) as total3,
SUM(IF(ticket.type_id = 4, 1, 0)) as total4,
SUM(IF(ticket.type_id = 5, 1, 0)) as total5
FROM
ticket
JOIN
ticket_type ON ticket_type.id = ticket.type_id
WHERE
DATE(ticket.created_date) BETWEEN '2015-06-12' AND '2015-06-22'
GROUP BY
DATE(ticket.created_date)
Current output:
Desired output:
As you see today is 2015-06-19. So my database currently have data only until right now (today). But if user's end_date is in future, i want get rows until that day, and datas will be 0.