将多个选择查询合并为一个查询

时间:2019-04-14 22:19:43

标签: sql sql-server tsql

我需要将多个选择语句分组为一个查询和多个列

我已经尝试使用UNION,但这会导致我的选择项之一丢失(可能是滥用了它)

SELECT COUNT(*) AS EMERGENCIA FROM Incidentes WHERE Prioridad_Real = 'Emergencia' AND Estado = 'Resuelto a Tiempo'
AND Fecha_Asigna >= '2013-08-22 13:30:00.000' and Fecha_Resul <= '2013-08-23 11:16:00.000'

SELECT COUNT(*) AS ALTA FROM Incidentes WHERE Prioridad_Real = 'Alta' AND Estado = 'Resuelto a Tiempo' 
AND Fecha_Asigna >= '2013-08-22 13:30:00.000' and Fecha_Resul <= '2013-08-23 11:16:00.000'

SELECT COUNT(*) AS MEDIA FROM Incidentes WHERE Prioridad_Real = 'Media' AND Estado = 'Resuelto a Tiempo'
AND Fecha_Asigna >= '2013-08-22 13:30:00.000' and Fecha_Resul <= '2013-08-23 11:16:00.000'

SELECT COUNT(*) AS BAJA FROM Incidentes WHERE Prioridad_Real = 'Baja' AND Estado = 'Resuelto a Tiempo'
AND Fecha_Asigna >= '2013-08-22 13:30:00.000' and Fecha_Resul <= '2013-08-23 11:16:00.000'

预期结果:

Expected result

1 个答案:

答案 0 :(得分:6)

尝试使用以下查询:

curl_slist_free_all(list);