我是mysql和php的新手。我想计算数字,并获得每个日期关闭的票的总和。我需要获得正确的计数和添加已关闭票证的查询。我非常感谢你的帮助。感谢
这是我的疑问:
SELECT ticket.tn, ticket.id, MAX(ticket_history.change_time) AS closed
FROM ticket_history
LEFT JOIN ticket_history_type ON (ticket_history_type.id = ticket_history.history_type_id)
LEFT JOIN ticket ON (ticket.id = ticket_history.ticket_id)
LEFT JOIN ticket_state ON (ticket_state.id = ticket_history.state_id)
LEFT JOIN ticket_state_type ON (ticket_state_type.id = ticket_state.type_id)
WHERE ticket_history_type.name = "StateUpdate" AND ticket_state_type.name="closed"
GROUP BY ticket.tn;
这是输出:
tn | id |关闭
2010080210123456 | 1 | 2013-10-21 09:45:43 。 。 。 。
这是我对计算已关闭的
的查询SELECT case when (select count(*) from ticket_history where ticket.tn, ticket.id,
MAX(ticket_history.change_time) AS closed
FROM ticket_history
LEFT JOIN ticket_history_type ON (ticket_history_type.id = ticket_history.history_type_id)
LEFT JOIN ticket ON (ticket.id = ticket_history.ticket_id)
LEFT JOIN ticket_state ON (ticket_state.id = ticket_history.state_id)
LEFT JOIN ticket_state_type ON (ticket_state_type.id = ticket_state.type_id)
WHERE ticket_history_type.name = "StateUpdate" AND ticket_state_type.name="closed"
GROUP BY ticket.tn;