有人可以帮助我进行此查询,我需要在此查询中应用u.a
和c.d
的分组:
SELECT DISTINCT u.a as ID,DECODE(u.b,'ACT','0','1') as STAT,
c.d AS role,
NVL(SUBSTR(c.d, 0, INSTR(c.d, '-')-1), c.d) as app,
SUBSTR(c.d, INSTR(c.d, ':') + 1) AS role
FROM dbo.USER u left outer join dbo.CONNECTION c on u.a = c.a
示例:
我们有两个表user
和connection
:
在user
中,数据将为:
id. Stat.
a1 1
a2 0
在connection
中,数据将为:
Id app. Role
a1 abc-d. Read
a3 cde-f. Write
a1 abc-d Read
因此,我需要基于id
进行左外部联接,然后需要基于两个键进行聚合,即Id
中的user
和{{1}中的role
}。
输出:
connection
答案 0 :(得分:0)
SELECT DISTINCT u.a as ID,DECODE(u.b,'ACT','0','1') as STAT,c.d AS
role,NVL(SUBSTR(c.d, 0, INSTR(c.d, '-')-1), c.d) as app,SUBSTR(c.d, INSTR(c.d,
':') + 1) as role FROM user u ,connection c where u.id=c id group by
u.a,SUBSTR(c.d, INSTR(c.d, ':') + 1)
您不能在group by子句中拥有列别名