表1 : A_ID
1
2
3
4
5
表2 : B_ID A_ID c_id
1 1 1
2 2 1
3 1 2
4 3 2
5 2 2
......
根据A_ID =(1,2,3...)满足表2的一个组合
注:A_ID的值为2-5个
结果如 1+2 ,1+2+3
求一个语句..分不够再加
1
2
3
4
5
表2 : B_ID A_ID c_id
1 1 1
2 2 1
3 1 2
4 3 2
5 2 2
......
根据A_ID =(1,2,3...)满足表2的一个组合
注:A_ID的值为2-5个
结果如 1+2 ,1+2+3
求一个语句..分不够再加
结果如 1+2 ,1+2+3
这什么意思
B表数据:
需要的数据:
--说明需要的数据是怎样计算得到的,然后我们帮你思考解决。
where zz.c_id=xx.c_id for xml path('')),1,1,'') from B xx
group by c_id
where zz.c_id=xx.c_id for xml path('')),1,1,'') from B xx
group by c_id)
select stuff((select ',' +aa from tb for xml path('')),1,1,'')
create table B( B_ID int ,A_id int,c_id int)
insert B values(1,1,1)
insert B values(2,2,1)
insert B values(3,1,2)
insert B values(4,2,2)
insert B values(5,3,2)
select * from A
select * from b
with tb as (select aa=STUFF((select '+'+cast(A_id as varchar(1)) from b zz
where zz.c_id=xx.c_id for xml path('')),1,1,'') from B xx
group by c_id)
select stuff((select ',' +aa from tb for xml path('')),1,1,'')
drop table a
drop table b