我有一个选择陈述
(select * from xxxx where yyy = '2011') AS a
INNER JOIN
(select * from xxx where yyy= '2010') AS b
ON a.yyy = b.yyy AND a.xxx = b.xxx)
有效。
如何将只有一列的结果插入另一个表?
我尝试用select.... INTO xxx
包含此内容,但它抱怨语法
答案 0 :(得分:0)
虽然您的特定查询不会返回任何结果,并且语法也是错误的,但如果您正在寻找一种方法将数据从SELECT
语句插入(临时)表中,您可以执行以下操作:
SELECT your_columns
INTO new_table
--or you can use a temp table
--INTO #table
FROM another_table
所以在你的情况下,它会是这样的:
SELECT *
INTO new_table
FROM
(select * from xxxx where yyy = '2011') AS a
INNER JOIN
(select * from xxx where yyy= '2010') AS b
ON a.yyy = b.yyy AND a.xxx = b.xxx
答案 1 :(得分:0)
SELECT * INTO new_table_name FROM table_name
应该可以正常使用。
如果你尝试输出是什么:
SELECT tmp.* INTO new_table_name FROM
(
(SELECT * FROM xxxx WHERE yyy = '2011') AS a
INNER JOIN
(SELECT * FROM xxx WHERE yyy= '2010') AS b
ON a.yyy = b.yyy AND a.xxx = b.xxx
) tmp