sql >> Base de Datos >  >> RDS >> Oracle

obtener el resultado de la consulta

Puedes usar SUM/CASE o (SUM/DECODE si lo prefieres)

Select
   COUNT(*) TOTAL_RECORDS  ,
   SUM(case when status = 'PENDING' then 1 else 0 END) TOTAL_PENDING, 
   SUM(case when status = 'NOT_REQUIRED' then 1 else 0 END) TOTAL_NOT_REQUIRED, 
   SUM(case when status = 'ERROR' then 1 else 0 END) TOTAL_ERROR


FROM temp25

Vea cómo funciona aquí

También puede usar pivot pero obtener el conteo (*) es un poco feo

WITH 
COUNTS AS(
select * 
from (
   select status
   from TEMP25 t
)
pivot 
(
   count(status)
   for status in ('PENDING' AS TOTAL_PENDING,
                  'NOT_REQUIRED' AS TOTAL_NOT_REQUIRED,
                  'ERROR' AS TOTAL_ERROR)
))


SELECT COUNT(*) total_records, 
       total_pending, 
       total_not_required, 
       total_error 
FROM   temp25, 
       counts 
GROUP  BY total_pending, 
          total_not_required, 
          total_error 

Versión dinámica