› Fóruns › SQL e PL/SQL › help sintaxe/ select max › help sintaxe/ select max
@marciommr
Faltou fechar um parenteses:
select distinct
c.cd_atendimento atendimento,
d.nm_paciente paciente,
b.cd_pro_fat procedimento,
e.ds_pro_fat ds_profat,
b.dt_lancamento data,
to_char (b.vl_unitario,'9,9999.99') valor_fat,
b.qt_lancamento qnt
from reg_fat a,itreg_fat b,atendime c,paciente d,pro_fat e,produto f,custo_medio g,
(
select *
from custo_medio cm
where cm.dh_custo_medio in (select max(cm.dh_custo_medio) from custo_medio a where a.cd_produto = cm.cd_produto )
)
where a.cd_reg_fat=b.cd_reg_fat
and c.cd_atendimento=a.cd_atendimento
and d.cd_paciente=c.cd_paciente
and e.cd_pro_fat=b.cd_pro_fat
and f.cd_produto=g.cd_produto
and f.cd_pro_fat=b.cd_pro_fat(+)
and c.cd_atendimento='260617'
and b.cd_pro_fat='08019208'