gpt4 book ai didi

sql - 将一个表中的选定列插入到 SQL Server 中另一个表的选定列

转载 作者:行者123 更新时间:2023-12-05 03:10:13 25 4
gpt4 key购买 nike

我是 SQL Server 的新手,想找到解决方案。

我有两个表 employeesnew_employees

employees 有列:

id(pk) | username | phonenumber | createdby | deptid |date

new_employees 有列:

id(pk) | name, p_number | dept_id | ext_no | salary

我想插入表 new_employees 中的所有记录,其中包含选定的列 namep_numberdept_id'employees 表的 usernamephonenumberdeptid 列。

但是在 employees 表的 createdbydate 列中,我想输入两个值 'John' 和 getDate() ;

请帮我写下这个场景的查询。

最佳答案

如果混淆来自表中的值和文字值,那么您可以使用这种形式的语法:

INSERT INTO Table (...)
SELECT col1, ... 'John', GetDate()
FROM AnotherTable;

关于sql - 将一个表中的选定列插入到 SQL Server 中另一个表的选定列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40690835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com