oracle的wmsys.wm_concat函数 和(+)连接转成sqlserver2005的

2025-03-04 22:30:25
推荐回答(3个)
回答1:

1. from tm_role r, tm_role_user_r ru
where ru.role_id = r.role_id(+)
这个其实就是 Left outer join
from tm_role_user_r ru left outer join tm_role r
on ru.role_id = r.role_id

2.wm_concat,这个用 stuff可以替代

-- 查询处理
--SQL2005中的方法2
create table tb(id int, value varchar(10))
insert into tb values(1, 'aa')
insert into tb values(1, 'bb')
insert into tb values(2, 'aaa')
insert into tb values(2, 'bbb')
insert into tb values(2, 'ccc')
go

select id, [values]=stuff((select ','+[value] from tb t where id=tb.id for xml path('')), 1, 1, '')
from tb
group by id

回答2:

  1.  from tm_role r, tm_role_user_r ru
                where ru.role_id = r.role_id(+)

    这个其实就是 Left outer join

     from tm_role_user_r ru left outer join tm_role r

                on ru.role_id = r.role_id


  2. wm_concat,这个用 stuff可以替代,我给你复制一段,你自己看看:


-- 查询处理   

--SQL2005中的方法2   

create table tb(id int, value varchar(10))  

insert into tb values(1, 'aa')  

insert into tb values(1, 'bb')  

insert into tb values(2, 'aaa')  

insert into tb values(2, 'bbb')  

insert into tb values(2, 'ccc')  

go   

  

select id, [values]=stuff((select ','+[value] from tb t where id=tb.id for xml path('')), 1, 1, '')  

from tb  

group by id

回答3:

1. from tm_role r, tm_role_user_r ru
where ru.role_id = r.role_id(+)
这个其实就是 Left outer join
2. from tm_role_user_r ru left outer join tm_role r
on ru.role_id = r.role_id

wm_concat,这个用 stuff可以替代,我给你复制一段,你自己看看:

-- 查询处理
--SQL2005中的方法2
create table tb(id int, value varchar(10))
insert into tb values(1, 'aa')
insert into tb values(1, 'bb')
insert into tb values(2, 'aaa')
insert into tb values(2, 'bbb')
insert into tb values(2, 'ccc')
go

select id, [values]=stuff((select ','+[value] from tb t where id=tb.id for xml path('')), 1, 1, '')
from tb
group by id