A表格:
A B C
11 22 33
aa bb cc
dd ee ffB表格(一个字段):
A
xx
yy
zzA表记录数量和B表的相同,A表的C字段和B表的唯一一个字段A属性相同,
现在要把B表的A字段,复制到A表成为A表的C字段,也就操作之后A表结构如下:
A表格:
A B C
11 22 xx
aa bb yy
dd ee zz
A B C
11 22 33
aa bb cc
dd ee ffB表格(一个字段):
A
xx
yy
zzA表记录数量和B表的相同,A表的C字段和B表的唯一一个字段A属性相同,
现在要把B表的A字段,复制到A表成为A表的C字段,也就操作之后A表结构如下:
A表格:
A B C
11 22 xx
aa bb yy
dd ee zz
解决方案 »
- 求分组求中间值的SQL
- sql中case when的用法
- 求一个高难度财务方面的SQL或存储过程
- excel或dbf导入mssql时的问题
- 在查询分析器里面提示 对象名 “department” 无效(其中department是数据库中的一个表,连接的数据库已经改为这个表所在的数据库)
- ●●●一个多表查询的问题,可能很简单,希望关注,很快结帖●●●
- 谢谢大家了!求一自动生成年月日+每张单据加一的触发器!谢谢拉!
- 急,hibernate统计问题
- 谁有中文OLEDB教程?
- SQL怎么改变字段名排列方向为纵向
- 数据插入问题(在线等,急!)
- @identity只在insert时返回标识,如果要返回updata最后的记录怎么办?
go
alter table b add id int identity(1,1)
goupdate a
set c=b.a
from a,b
where a.id=b.idalter table a drop column id
go
alter table b drop column id
go
insert T1 select '11', '22', '33'
union all select 'aa', 'bb', 'cc'
union all select 'dd', 'ee', 'ff'create table T2(A varchar(10))
insert T2 select 'xx'
union all select 'yy'
union all select 'zz'declare cur cursor for
select A, B, C from T1
for update of Cdeclare @fetch_status int
declare @i int
set @i=1open curfetch cur select @fetch_status=@@fetch_statuswhile @@fetch_status=0
begin
update T1 set C=
(
select A from T2 as tmp
where @i=(select count(1) from T2 where A<=tmp.A)
)
where current of cur fetch cur select @fetch_status=@@fetch_status
set @i=@i+1
end close cur
deallocate curdrop table T1
drop table T2
where @i=(select count(1) from T2 where A<=tmp.A)
上面的语句什么意思啊?
112233
aabbcc
ddeeffB表格(一个字段):
A
xx
yy
zz
------------------
select *,identity(int,1,1) TID into #a from a
select *,identity(int,1,1) TID into #b from b
update a
set c=a.c+b.a
from #a a
inner join #b b
on a.TID=b.TIDdrop table a
select a,b,c into a from #a
drop table #a
drop table #b