我怎样才能改变我的输出返回的方式,使其全部在一行上呢?现在if有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'

发布于 2015-09-24 22:03:19
这通常通过添加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 1https://stackoverflow.com/questions/32762827
复制相似问题