有关SQL关联合并数据的问题

[复制链接]
查看11 | 回复1 | 2008-9-4 10:15:26 | 显示全部楼层 |阅读模式
drop table #temp1,#temp2
create table #temp1
(
a varchar(30),
b varchar(30)
)
create table #temp2
(
c varchar(30),
d varchar(30),
e int
)
insert into #temp1
select '#1', 'a,b,c'
union all
select '#1', 'd,e,f'
insert into #temp2
select '#1', 'a', 1
union all
select '#1', 'b', 2
union all
select '#1', 'c', 3
union all
select '#1', 'd', 4
union all
select '#1', 'e', 5
union all
select '#1', 'f', 6
select * from #temp1
select * from #temp2
-- 想得到结果:
-- #1 a,b,c 6
-- #1 d,e,f 15
1、首先非常感谢rainee007的回答
2、实现我也已经实现,只是用游标,不理想,想用一些比较简单的语句来实现。
3、项目已经上线,改变结构的思路是好的,但已不现实。

回复

使用道具 举报

千问 | 2008-9-4 10:15:26 | 显示全部楼层
可以实现你的要求,但是如果是这个需求,你的表设计很不合理,实现起来很麻烦,如果不是考题的话,最好重新设计表结构...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行