Jump to content
Fórum Script Brasil
  • 0

Exibir Dias nulos


Question

Boa tarde!

 

Pessoal, estou tentando fazer um select no banco que me retorne todos os dias do mês, mesmo os que não tiverem informação, preenchendo com 0 ou null,

segue sql que fiz:
SELECT es.nome, COALESCE(EXTRACT(DAY FROM a.horario) ,0)as Dia, count(*) as qtd
FROM agenda a
LEFT JOIN escala e ON a.escala_id = e.id
LEFT JOIN especialidade es ON a.especialidade_codigo = es.codigo
WHERE (CAST(a.horario as DATE) >= '01/07/2019') AND (CAST(a.horario as date) <= '31/07/2019')
AND (a.especialidade_codigo = '42' OR a.especialidade_codigo = '43' OR a.especialidade_codigo = '44')
AND a.status_agenda = 'CONFIRMADO'
AND e.tipo_escala = 'CONSULTA'
AND a.encaminhamento_atendimento_id = 1
GROUP BY es.nome, Dia
ORDER BY Dia;

 

Retorno do banco:
"nome"                   "dia"   "qtd"
"CARDIOLOGIA"    "1"      "12"
"CARDIOLOGIA"    "2"      "7"
"CARDIOLOGIA"    "4"      "6"
"CARDIOLOGIA"    "5"      "6"
"CARDIOLOGIA"    "11"    "7"
"CARDIOLOGIA"    "12"    "7"
"CARDIOLOGIA"    "15"    "4"
"CARDIOLOGIA"    "16"    "6"
"CARDIOLOGIA"    "18"    "4"
"CARDIOLOGIA"    "19"    "6"
"CARDIOLOGIA"    "22"    "6"
"CARDIOLOGIA"    "23"    "6"
"CARDIOLOGIA"    "25"    "5"
"CARDIOLOGIA"    "26"    "7"
"CARDIOLOGIA"    "27"    "1"
"CARDIOLOGIA"    "29"    "6"

Grato

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Cloud Computing


  • Forum Statistics

    • Total Topics
      148681
    • Total Posts
      644509
×
×
  • Create New...