选择重复数据并显示为表格

时间:2013-11-26 09:36:36

标签: sql oracle report left-join

我正试图在这样的cuser表中显示数据

a_User
___________________
1, Ben,

2, Joe,

3, Tom,

User_group
______________
1, 1,

1, 2,

1, 3,

2, 2,

3, 1,

a_Group
________________
1, All Access,

2, Customer Service,

3, Finance,

所以它弹出像

____________________________________________

Ben, All Access, Customer Service, Finance

Joe, null, Customer Service, null

Tom, All Access, null, null

相反,我正在

____________________________________________

Ben, All Access, All Access, All Access,
Ben, Customer Service, Customer Service, Customer Service,
Ben, Finance, Finance, Finance
Joe, Customer Service, Customer Service, Customer Service,
Tom , All Access, All Access, All Access,

我一直在加入一个左外连接,但我不能让列与描述相关联。

select su.usernum,
  su.username,
  su.descr,
  su.email,
  sfg1.functiongroup,
  sfg2.functiongroup,
  sfg3.functiongroup
from a_user su
left outer join User_group suf on su.usernum = suf.usernum
left outer join a_group sfg1 on suf.fgroupnum = sfg1.fgroupnum
left outer join a_group sfg2 on suf.fgroupnum = sfg2.fgroupnum
left outer join a_group sfg3 on suf.fgroupnum = sfg3.fgroupnum
where sfg1.FGROUPNUM = 1
  or sfg2.FGROUPNUM = 2
  or sfg3.FGROUPNUM = 3;

任何想法都会非常方便,

感觉我错过了一些非常基本的东西。

1 个答案:

答案 0 :(得分:0)

在Oracle 11.2中,您可以使用新功能LISTAGG

但是在Oracle 10中没有这个功能(不支持,顺便说一下),你必须在我猜的函数中编写它。