如何分组而不汇总?

时间:2019-03-14 16:12:57

标签: sql oracle group-by oracle-sqldeveloper

我正在尝试编辑我的sql,以便它将根据role_name列显示gl_name,bu_name和gl_name2列。我无法进行分组,因为我没有汇总。最好的方法是什么?现在是这些结果:

enter image description here

我期望的结果是一行将所有内容组合在一起,如下所示:

enter image description here

我的SQL:

select
pu.username,
role.ROLE_NAME,
gl.name gl_name,
bu.bu_name bu_name,
led.NAME gl_name2
from 
FUN_USER_ROLE_DATA_ASGNMNTS role,
gl_access_sets gl,
per_users pu,
FUN_ALL_BUSINESS_UNITS_V bu,
GL_LEDGERS led
where gl.ACCESS_SET_ID (+)= role.ACCESS_SET_ID 
and role.org_id = bu.bu_id (+)
and role.LEDGER_ID = led.LEDGER_ID (+)
and pu.USER_GUID = role.USER_GUID (+)
and role.role_name IS NOT NULL
and (gl.name IS NOT NULL or bu_name IS NOT NULL or led.name IS NOT NULL)
order by pu.username, role.role_name

1 个答案:

答案 0 :(得分:2)

如果我理解得很好,您可能只需要这个:

select username, role_name, max(gl_name), max(bu_name), max(gl_name2)
from 
     ...
group by username, role_name
order by username, role_name