DECLARE @T1 TABLE(COL1 VARCHAR(1)) DECLARE @T2 TABLE(COL2 VARCHAR(5),COL3 VARCHAR(1)) INSERT @T2 SELECT 'red','A' UNION ALL SELECT 'red','B' UNION ALL SELECT 'red','C' UNION ALL SELECT 'black','A' INSERT @T1(COL1) SELECT COL3 FROM @T2 WHERE COL2='red' SELECT * FROM @T1COL1 ---- A B C
insert into tab1(col1) select col3 from tab2 where col2='red'
--从后往前理解 --1:找到tab2中所有Col2为"red"的行的Col3字段 select col3 from tab2 where col2='red' --2:插入到tab1的col1字段中 insert tab1(col1)select col3 from tab2 where col2='red'
表Tab2中所有Col2为"red"的行的Col3字段; ------------------------------------------ 说明可能不只一行,有N行insert into tab1(col1)select col3 from tab2 where col2='red' 把N行插入到一个字段中,结果是怎样的?
--写一SQL语句,向表Tab1中Col1字段插入表Tab2中所有Col2为"red"的行的Col3字段; insert into Tabl1(Col1) select Col3 from Tab2 where Col2='red'
有N行就在tab1生成N行 可以看2楼的测试数据
insert into tab1(col1) select col3 from tab2 where col2 = 'red'
这个好像在考试语文理解能力,干脆弄个文言文让翻译一下多好!写的这么复杂,有意思〉!insert into tab1(col1) select col3 from tab2 where col2 = 'red'
insert into tab1(col1) select col3 from tab2 where col2='red'
insert into tab1(col1) select col3 from tab2 where col2 = 'red'
我理解是: 先找到表Tab2所有Col2字段为"red"所对应的Col3字段行,再把Col3字段行的数据插入表Tab1中Col1字段 insert into Tab1 select Col3 from Tab2 where Col2='red'
写一SQL语句,向表Tab1中Col1字段插入表Tab2中所有Col2为"red"的行的Col3字段;insert into Tab1 select Col3 from Tab2 where Col2='red'应该是这样吧?
insert tab1(col1) select col3 from tab2 where col2 = 'red'
DECLARE @T2 TABLE(COL2 VARCHAR(5),COL3 VARCHAR(1))
INSERT @T2 SELECT 'red','A'
UNION ALL SELECT 'red','B'
UNION ALL SELECT 'red','C'
UNION ALL SELECT 'black','A'
INSERT @T1(COL1) SELECT COL3 FROM @T2 WHERE COL2='red'
SELECT * FROM @T1COL1
----
A
B
C
--1:找到tab2中所有Col2为"red"的行的Col3字段
select col3 from tab2 where col2='red'
--2:插入到tab1的col1字段中
insert tab1(col1)select col3 from tab2 where col2='red'
------------------------------------------
说明可能不只一行,有N行insert into tab1(col1)select col3 from tab2 where col2='red'
把N行插入到一个字段中,结果是怎样的?
insert into Tabl1(Col1) select Col3 from Tab2 where Col2='red'
可以看2楼的测试数据
先找到表Tab2所有Col2字段为"red"所对应的Col3字段行,再把Col3字段行的数据插入表Tab1中Col1字段
insert into Tab1
select Col3 from Tab2
where Col2='red'
select Col3 from Tab2
where Col2='red'应该是这样吧?
insert tab1(col1) select col3 from tab2 where col2 = 'red'
select col3 from tab2 where col2='red'
select col3 from tab2 where col2='red'
- -!我怎么觉得这问题本身就有问题!!Col2是字段吧?"red"的行是Col2的值吗?那这个Col2"red"的行的Col3字段是哪来的?本人技术不行,问题比较多,望指教!!
insert into tab1(col1) select col3 from tb2 where col2='red'