如何在1个表中执行多个SQL查询?

时间:2014-12-16 21:35:36

标签: mysql sql subquery mysql-workbench

我想在1个语句中运行3个不同的查询。表中是否有NULL值无关紧要。

示例:

(SELECT ticket_state.name AS 'Ticket State',
        COUNT(ticket.ticket_state_id) AS 'Number of Active Request'
FROM Ticket
INNER JOIN ticket_state ON ticket.ticket_state_id = ticket_state.id  
WHERE (ticket_state_id = 1
      OR ticket_state_id = 4
      OR ticket_state_id = 10
      OR ticket_state_id = 11)
GROUP BY ticket.ticket_state_id);

(SELECT
    SUM(ticket.queue_id = 12) AS 'Closed at HelpDesk',
    COUNT(ticket.id) AS 'Total Closed Ticket',
    (SUM(ticket.queue_id = 12) / COUNT(ticket.queue_id) * 100) AS 'Percent Closed at Helpdesk' 
FROM ticket
WHERE (ticket_state_id = 3 OR ticket_state_id = 2))

我想在一个表中查询两个查询!

0 个答案:

没有答案