select distinct o.type,t1.name,t2.name from order o with(nolock) left join table1 t1 on t1.orderid=o.id left join table2 t2 on t2.orderid=o.id
我想实现,如果o.type等1就left join table1,否则的话就left join table2
用一个sql语句要咋写啊?
8 回答
Helenr
TA贡献1780条经验 获得超4个赞
@幻天芒: 我是想用你这个语句。
可是我只想输出TransactionID,PrepayType,PaymentCatalog这要怎么写呢
select distinct t1.TransactionID,t1.PrepayType,t1.PaymentCatalog,
t2.ExternalNo as TransactionID,t2.PaymentWay as PrepayType,t2.PaymentCatalog
from order o with(nolock)
left join table1 t1 on t1.orderid=o.id and o.type=1
left join table2 t2 on t2.orderid=o.id and o.type<>1
我这样写输出的是6列,是不是只有union才能输出3列啊?
- 8 回答
- 0 关注
- 539 浏览
添加回答
举报
0/150
提交
取消