如何将输出从2行合并到1行?

时间:2015-09-24 13:36:00

标签: teradata

如何更改输出的输出方式以便在一行中完成所有操作?现在如果有2行。两者中RA等于1KK8888,一行中的费用和第二行中的费率。

select  

                ,FRP.rent_doc_cd as Contract
                ,case when charge.charge_id = 7213 then charge.chg_amt else 0 end as FEE
                ,case when charge.charge_id = 7220 then charge.chg_amt  else 0 end as Rate


    FROM intgX.RENTAL_Tbl FRP                                                                 
    left join intgX.RENTAL_CHG charge  on FRP.renalt_document = charge.rental_document and charge.charge_cd in (7213,7220)
    where  FRP.renalt_chg = '1KK8888'

enter image description here

1 个答案:

答案 0 :(得分:0)

这通常通过添加MAX加GROUP BY来完成:

select  
     ,FRP.rent_doc_cd as Contract
     ,max(case when charge.charge_id = 7213 then charge.chg_amt else 0 end) as FEE
     ,max(case when charge.charge_id = 7220 then charge.chg_amt  else 0 end) as Rate


FROM intgX.RENTAL_Tbl FRP                                                                 
left join intgX.RENTAL_CHG charge  on FRP.renalt_document = charge.rental_document and charge.charge_cd in (7213,7220)
where  FRP.renalt_chg = '1KK8888'
group by 1