Pular para o conteúdo

Fóruns SQL e PL/SQL help sintaxe/ select max help sintaxe/ select max

#104756
Marcio Rodrigues
Participante

    Coloquei a sintaxe (MAX), mas ainda retorna erro, como realizar esta consulta?

    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 custo.vl_custo_medio=max(custo.dt_custo)
    from custo_medio custo where custo.cd_produto = g.cd_produto group by custo.vl_custo_medio) custo

    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′