1
I need to pass all the values of a clause IN
, for a subselect
one-column.
Ex:
SELECT distinct
'Atendimentos' Tipo,
to_char(A.DT_ATENDIMENTO, 'mm/yyyy') Competencia,
pre.cd_prestador,
se.cd_setor,
se.nm_setor,
(
select (count(distinct a2.cd_atendimento)) --* 0.3
from atendime a2
INNER JOIN PRESTADOR Pre2 ON A2.CD_PRESTADOR =
Pre2.CD_PRESTADOR
left join setor se2 on se2.CD_SETOR =
a2.cd_setor
where to_char(a2.DT_ATENDIMENTO, 'mm/yyyy') =
to_char(a.DT_ATENDIMENTO, 'mm/yyyy')
and pre2.cd_prestador = pre.cd_prestador --Aqui é o problema
and se2.cd_setor = se.cd_setor
group by to_char(A.DT_ATENDIMENTO, 'mm/yyyy')
) total
FROM ATENDIME A
INNER JOIN PRESTADOR Pre ON A.CD_PRESTADOR = Pre.CD_PRESTADOR
left join setor se on se.CD_SETOR = a.CD_SETOR
where to_char(A.DT_ATENDIMENTO, 'mm/yyyy') = '08/2018'
and pre.cd_prestador in (127,3921,1704,28,5048,3118,130,3336,2171,1869,128,132,186)
order by se.cd_setor
I need this last column to bring me the overall total of appointments. No where
of subselect
(column with the alias "total"), I compare the competence with the competence of the select
external, and the sector with the external select sector. So far, everything normal. The problem is the provider, who, if there was only one, would just stay the way it is up there. However, I need the comparison to be made with all the values that are passed in the clause IN
of the external select.
Thanks in advance.
His image editing of the code impoverished the publication, so I just formatted and identei his
query
– Sorack
If I understood the problem I would just exchange in subselect the cd_provider = for a replication of the "in" ... the aggregator will be for the total.
– Motta
Yes. Doing the query in an editor, it would work. But the query goes to a report, you can’t keep these fixed numbers.
– Vinicius Masson
https://forum.imasters.com.br/topic/289781-concatenar-valores/? do=findComment&comment=1053697 see if it helps ... but your problem is the same with a single query...
– Motta