我正在编写一个用于创建碧玉报告的 oracle 10g 查询。
这是查询 -
SELECT essay_id,
LTRIM (
MAX (SYS_CONNECT_BY_PATH (full_name, ','))
KEEP (DENSE_RANK LAST ORDER BY curr),
',')
AS full_name
FROM (SELECT essay_id,
full_name,
ROW_NUMBER () OVER (PARTITION BY essay_id ORDER BY full_name)
AS curr,
ROW_NUMBER ()
OVER (PARTITION BY essay_id ORDER BY full_name)
- 1
AS prev
FROM (SELECT a.id AS essay_id,
CASE NVL (firstname, 'NULL FIRSTNAME')
WHEN 'NULL FIRSTNAME' THEN username
ELSE (firstname || ' ' || lastname)
END
AS full_name
FROM essay_table a
INNER JOIN essay_writer_join ej ON a.id = ej.essay_id
INNER JOIN writer_table u ON ej.user_id = u.id))
GROUP BY essay_id
CONNECT BY prev = PRIOR curr AND essay_id = PRIOR essay_id
START WITH curr = 1
这些文章是独一无二的,但可以有多个作者 (essay_writer_join) 此查询为我提供了由逗号分隔的作者的文章。
问题是我需要再添加一个名为“manager”的列,它将显示作者的经理。经理信息位于列名为“manager_name”的 WRITER_TABLE 中。文章表有作者的名字、姓氏和用户名。棘手的部分是 2 位作家可以有 2 位不同的经理。例如,对于文章“123”,作者是“abc”和“xyz”,这些作者的管理者分别是“lmo”和“pqr”,那么记录应以下列格式显示
essay id writer manager
123 abc, xyz lmo, pqr
这在 oracle 10g sql 中可能吗?我试图搜索类似的情况,但找不到任何相关的解决方案。