从表中的Sql条件... [英] Sql condition inside from table on ...
本文介绍了从表中的Sql条件...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很好奇是否可以在from table部分中添加一个条件。
我需要的是这样的东西select * from table A inner在表B上加入if(B.column =this)A.column = B.Column1 else A.column = B.column2。
整个查询由CTE组成,我可以通过在最终选择中添加第三个来解决这个问题,但我很好奇是否有可能这样做。
I'm curious if it's possible to add a condition inside the from table part.
What I would need is something like this select * from table A inner join on table B on if(B.column = "this") A.column = B.Column1 else A.column = B.column2.
The entire query consists of to CTE's and I can probably work around this by adding a third one in to the final selection but I was curious if it was possible doing it like this.
推荐答案
你好,
你可以这样试试
Hello ,
You may try like this way
select * from table A inner join table
B on A.column= case when B.column ='this' then B.Column1 else B.column2 end
查看有条件的加入SQL Server [ ^ ]接近结尾的例子应该有所帮助。
Check this out Conditional Joins in SQL Server[^] the example nearing the end should help.
这篇关于从表中的Sql条件...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文