如何:插入并选择-但其中一个字段来自其他地方? [英] how to: insert into, select - but one field is from somewhere else?

查看:58
本文介绍了如何:插入并选择-但其中一个字段来自其他地方?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是插入的方式,选择通常是有效的 (示例摘自: https://stackoverflow.com/a/576442/101055 ):

this is how insert into, select is usually working (example taken from: https://stackoverflow.com/a/576442/101055):

INSERT INTO new_table (Foo, Bar, Fizz, Buzz)
SELECT Foo, Bar, Fizz, Buzz
FROM initial_table

但是-如果Fizz不在initial_table中,而是变量@fizz,怎么办?

BUT - how to do this if Fizz is not in the initial_table, but is a variable @fizz?

失败:

INSERT INTO new_table (Foo, Bar, @fizz, Buzz)
SELECT Foo, Bar, Buzz
FROM initial_table

thnx

推荐答案

INSERT INTO new_table (Foo, Bar, Fizz, Buzz)
SELECT Foo, Bar, @fizz, Buzz
FROM initial_table

插入语法为

insert into destination_table (destination_colum1, destination_colum2, ...)
select source_value1, source_value2, ...  from source_table

首先,将要写入的列命名为,然后选择源

First you name the columns you want to write into and then you select the source

这篇关于如何:插入并选择-但其中一个字段来自其他地方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆