希望這有助於你:
insert into t_department values(1, 'MANAGER');
insert into t_department values(2, 'OTHERS');
insert into t_employee values(1, 1, NULL ,'NAME-1', 50000, sysdate, 'ADDRESS','Y');
insert into t_employee VALUES(2, 2, NULL, 'NAME-2', 40000, SYSDATE, 'ADDRESS','Y');
insert into t_employee values(3, 2, null, 'NAME-3', 50000, sysdate-200, 'ADDRESS','Y');
insert into t_employee values(4, 2, null, 'NAME-4', 40000, sysdate-100, 'ADDRESS','Y');
insert into t_employee values(5, 2, null, 'NAME-5', 40000, sysdate-100, 'ADDRESS','Y');
insert into t_employee values(6, 2, null, 'NAME-6', 40000, sysdate-100, 'ADDRESS',NULL);
select to_char(birth_date, 'mon') "month",
LISTAGG(e.name||'('||NVL(e.status,'Not Defined')||')', ',') WITHIN GROUP (
ORDER BY TO_CHAR(BIRTH_DATE, 'mon')) AS lists
FROM t_employee e
JOIN t_department d
ON(e.department_id = d.id)
where d.name <> 'MANAGER'
GROUP BY TO_CHAR(BIRTH_DATE, 'mon');
MONTH LISTS
------------ ------------------------------------------
apr NAME-3(Y)
jul NAME-4(Y),NAME-5(Y),NAME-6(Not Defined)
oct NAME-2(Y)
或者乾脆:
select to_char(birth_date, 'mon') month, nvl(e.status,'Not Defined')status,
listagg(e.name, ',')
WITHIN GROUP (ORDER BY TO_CHAR(BIRTH_DATE, 'mon')) AS lists
FROM t_employee e
JOIN t_department d
ON(e.department_id = d.id)
where d.name <> 'MANAGER'
group by to_char(birth_date, 'mon'),e.status;
MONTH STATUS LISTS
------------ -------------------------------- -------
apr Y NAME-3
jul Not Defined NAME-6
jul Y NAME-4,NAME-5
oct Y NAME-2
要打印管理器的列表或計數
?如果你分組,你無法獲得一個列表!沒有必要使用第二個表格,這兩個表格之間的關係是什麼?發佈示例數據以及迄今爲止嘗試過的內容 – SriniV
您是否可以編輯您的問題並添加您嘗試過的代碼以獲得結果?我們不想爲那些甚至沒有嘗試過的人浪費我們的努力。 – Rachcha