1
Thanks to the help of Motta I managed to arrive in a satisfactory query but I ran into another question because, I need to list only the smallest record for cod
, and count the amount of the column menorregistro
by name.
Could someone help?
Follow the return of the query for exemplification:
That is, I need you to list only the lines with the Menorregister column = 558, 896 and 1321. And to count the Menorregistro by name staying that way:
Note: I don’t need the column DT_ATE and even list which was the smallest record I just want to count how many smaller records each name had, I left the columns only to better exemplify the problem.
Follow the query:
select b.pront as cod,
d.nome,
b.dt_ate,
min(case when b.dt_ate between '19.12.2015' and '08.01.2016' then b.reg else null end) menorRegistro
from recadate b
inner join tbcbopro c on b.crm=c.cod
inner join tbprofis d on c.id_tbprofis=d.id
where b.conv between :ConvInicial and :ConvFinal
and b.unidade between :Unidade_inicial and :Unidade_final
and b.pront in (111811, 210313, 395415)
group by d.nome, b.pront, b.reg, b.dt_ate
having min(case when b.dt_ate between '19.12.2015' and '08.01.2016' then b.reg else null end) is not null
Would that be something like? http://answall.com/questions/131637/buscar-somente-o-menor-n%C3%Bamero-de-every-letter/131640#131640
– Marconi
Hello Marconi, I just removed the dt_ate and it is listing correctly now as in the second image, but I need to count the column menorRegistro being that this column is an aggregated function min, I do not know how to do already researched a lot..
– Daruich Campideli
Managed to solve your problem ?
– Marco Souza