基于模式的SQL表

omdurg:

我有一个像这样的表:

source    target              
jan       feb                               
mar       apr                 
jun                       
feb       aug                                            
apr       jul                                            
oct       dec                     
aug       nov       
dec       may                               

输出(我要在其中创建new_target列的位置):

source    target    new_target              
jan       feb       aug                        
mar       apr       jul                  
jun                              
feb       aug       nov                                     
apr       jul                                                  
oct       dec       may              
aug       nov       
dec       may      

目的是new_target根据类似的逻辑创建列-例如,janin源中的值febin target这反过来,feb在源具有值augtargetaug具有novtarget柱所以new_target列将具有第三值:即(痕量随后源和目标之间jan->feb->aug->nov,由于aug是第三值,则在输出new_target列)

戈登·利诺夫(Gordon Linoff):

这看起来像left join

select t.*, tnext.target
from t left join
     t tnext
     on t.target = t.next.source

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章