sql中如何将相同字段的其它字段拼接在一起放到另一个字段里面的方法。
如下参考:
1.将新表select*的表结构和数据程度从源表名复制到目标表名中(需要不存在目标表,因为在插入查询时将自动创建它)如下图。
2.仅将表结构复制到新表CREATETABLE新表SELECT*FROM旧表WHERE1=2
3.将数据从旧表复制到新表(假设两个表结构相同),然后从旧表中插入新表SELECT*。
4.将旧表的数据复制到新表中(假设两个表结构不同),插入新表(字段1,字段2…)选择字段1,字段2…从旧桌子上,如下图。
5.Oracle数据库也类似,如下图。
看一下我的示例,是不是对你有帮助。
create table st_test ( id int ,name varchar(10),st varchar(100) )
insert st_test ( id,name )
select 1,'aa'
union select 1,'bb'
union select 1,'cc'
union select 2,'dd'
union select 3,'55'
union select 3,'777'
declare @c varchar(100)
declare @id int
declare cur_type cursor for
select distinct id from st_test
open cur_type
fetch cur_type into @id
while @@fetch_status = 0
begin
set @c = ''
select @c = @c + name from st_test f where f.id = @id
update st_test set st = @c
where id = @id
fetch cur_type into @id
end
close cur_type
deallocate cur_type
oracle就||
select ID||Name from person
是T-1,T-2,T-3这样吗?f37中全放也可以吧