有两张表TABLE1,TABLE2.
TABLE1的字段如下:
CD NM
01 上海
02 浙江
TABLE2的字段如下:
CD1 CD2
01 02
select a.*,b.nm as NM1,c.nm as NM2 from TABLE2 a
left join TABLE1 b on b.cd=a.cd1
left join TABLE1 c on c.cd=a.cd2
如何把上面的SQL合并为只有一个LEFT的SQL?
XIEXIE!
------解决方案--------------------
select
max(case a.CD1 when b.CD then b.NM end),
max(case a.CD2 when b.CD then b.NM end)
from
TABLE2 a,
TABLE1 b
group by
a.CD1,a.CD2