繁体   English   中英

将数据从2列复制到另一个表中的1列MS SQL

[英]Copy data from 2 columns in to 1 column in another table MS SQL

我试图复制存储在比赛的获奖者tblFixtures中的一列tblEntrants 因此,我基本上希望这样的赢家列表在tblEntrants AccountID列中创建...

tblFixtures Columns: Player1 resultPLayer1 Player2 ResultPlayer2, CompID
                       john        5         stu         2        (Guid) 
                       dave        0         max         5        (Guid)

tblEntrants Columns: AccountID, CompID
                        john    (Guid)
                        dave    (Guid)

到目前为止,这是我尝试过的方法,但是没有用。

INSERT INTO tblEntrants(AccountID,compID) SELECT(CASE WHEN (SELECT resultplayer1 FROM tblfixtures) > (SELECT resultplayer2 FROM tblfixtures) THEN (SELECT player1 FROM tblfixtures) END), @compID

INSERT INTO tblEntrants(AccountID,compID) SELECT(CASE WHEN (SELECT resultplayer2 FROM tblfixtures) > (SELECT resultplayer2 FROM tblfixtures) THEN (SELECT player2 FROM tblfixtures) END), @compID

尝试:您可以在CASE使用单个SELECT语句来完成此操作

INSERT INTO tblEntrants(AccountID,compID)
SELECT
    CASE WHEN resultPLayer1 > ResultPlayer2 THEN player1 ELSE player2 END, @compID
FROM tblFixtures

您可以使用它。

INSERT INTO tblEntrants(AccountID,compID) 
SELECT CASE WHEN ResultPlayer2 > resultPLayer1 THEN Player2 ELSE Player1 END, CompID
FROM tblfixtures

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM