我是 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;
这是输出:
吨 | 编号 | 关闭
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;