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

Función agregada de Oracle SQL con valores predeterminados

Edite para incluir 0.

SELECT
  id_list.id,
  status_list.status,
  COUNT(counterTb.id)
FROM
(
  SELECT 3 AS id FROM dual
)
  id_list
CROSS JOIN
(
  SELECT 'YES' AS status FROM dual
  UNION ALL
  SELECT 'NO'  AS status FROM dual
)
  status_list
LEFT JOIN
  counterTb
    ON  counterTb.id     = id_list.id
    AND counterTb.status = status_list.status
GROUP BY
  id_list.id,
  status_list.status
ORDER BY
  id_list.id,
  status_list.status DESC