SQL问题:如何避免200个If-Else语句?

Jos*_*nel 5 sql ms-access

我跟随表的属性

Table1: [username]    [old_profile]
Table2: [old_profile] [new_profile]
Table3: [username]    [new_profile]    [some_more_attributes]
Run Code Online (Sandbox Code Playgroud)

表2声明了将"old_profile"重命名为"new_profile"的规则(例如,如果old_profile被称为"Banana300",则new_profile应该被称为"Chocolate125").

有谁知道是否可以使用SQL/MS Access Query执行该操作?

如果没有,我将不得不为此任务编写外部脚本.

非常感谢.

干杯

编辑:我忘了明确提到我想从Table1和Table2创建Table3(忽略"some_more_attributes").

Pat*_*rez 5

如果我理解你的问题:

INSERT INTO table3 (username, newprofile) 
SELECT t1.username, t2.newprofile
FROM table1 t1 INNER JOIN table2 t2 ON t1.oldProfile = t2.OldProfile
Run Code Online (Sandbox Code Playgroud)

  • @David:我是心灵读者;-) (2认同)