由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - SQL copy a table into a new table and add a new column (转载)
相关主题
sort two same tables SQL but different results (转载)SQL add some columns into a table from another table
求教一个SQL的问题被一个面试题卡的泪流满面 SQL
SQL combine two tables into one table and add a new column请教个SQL的问题
error of executing SQL query of string concatenation (转载SQL find distinct values in large table (转载)
sql的2个问题请教一道算法题目,请高手指点
SQL check likeness between two large tables (转载)Error of SQL query on IBM netezza SQL database from Aginity workbench
error of sql query in MS Access databaseSQL 面试题 - 请高手指点
SQL combine two columns from two different tables no shared columns问个sql 题
相关话题的讨论汇总
话题: table1话题: table话题: new话题: col1话题: table2
进入JobHunting版参与讨论
1 (共1页)
l******9
发帖数: 579
1
【 以下文字转载自 Database 讨论区 】
发信人: light009 (light009), 信区: Database
标 题: SQL copy a table into a new table and add a new column
发信站: BBS 未名空间站 (Fri May 23 12:05:22 2014, 美东)
need to copy a table into a new table on SQL server 2008. Also, add a new
column into the new table.
The values of the new column depends on the compare result between the new
table and another table.
Example,
Table1:
col1 col2 col3
abc 346 6546
hth 549 974
Table1_new:
col1 col2 col3 col4
abc 346 6546 1
hth 549 974 0
Table2:
col1
abc
sfsdf
If Table2's col1 appear in Table1 col1, mark col4 as 1 in Table1_new, else
mark as 0.
The code does not work
SELECT *,
(
SELECT 1 as col4
FROM Table2 as a
INNER JOIN Table1 as b
on b.col1 = a.col1
SELECT 0 as col4
FROM Table2 as a
INNER JOIN Table1 as b
on b.col1 <> a.col1 # I do not know how to do this !!!
)
INTO table1_new
FROM table1
Any help would be appreciated.
1 (共1页)
进入JobHunting版参与讨论
相关主题
问个sql 题sql的2个问题
请帮忙回答一个SQL问题SQL check likeness between two large tables (转载)
sql questionerror of sql query in MS Access database
SQL multiply all values of a column in table (转载)SQL combine two columns from two different tables no shared columns
sort two same tables SQL but different results (转载)SQL add some columns into a table from another table
求教一个SQL的问题被一个面试题卡的泪流满面 SQL
SQL combine two tables into one table and add a new column请教个SQL的问题
error of executing SQL query of string concatenation (转载SQL find distinct values in large table (转载)
相关话题的讨论汇总
话题: table1话题: table话题: new话题: col1话题: table2