我已經搜查了很多次,但我無法找到正確的查詢,以適應什麼,我試圖做的。在示例圖像中,我想將所有匹配的數據放入一行,並使用Apex Interactive Report應用程序中的pl/sql將推薦列下的數字與逗號相結合。
看起來像這樣:
0177 || Martinez的,梅爾喬|| 24-OCT-13 || || 1 17 || || 1,2,8
0178 || Saxon,Victoria || 16-OCT-13 || 2 || 748 || 4,5 ||
我已經搜查了很多次,但我無法找到正確的查詢,以適應什麼,我試圖做的。在示例圖像中,我想將所有匹配的數據放入一行,並使用Apex Interactive Report應用程序中的pl/sql將推薦列下的數字與逗號相結合。
看起來像這樣:
0177 || Martinez的,梅爾喬|| 24-OCT-13 || || 1 17 || || 1,2,8
0178 || Saxon,Victoria || 16-OCT-13 || 2 || 748 || 4,5 ||
alter session set nls_date_format = 'dd-MON-rr'; -- NOT PART OF THE QUERY
with test_data (subject_number, patient, mdt_date, pres_phys, cr_mdt_phys, recomm) as (
select '0177', 'Martinez, Melchior', to_date ('24-OCT-13'), 1, 17, 1 from dual union all
select '0177', 'Martinez, Melchior', to_date ('24-OCT-13'), 1, 17, 2 from dual union all
select '0177', 'Martinez, Melchior', to_date ('24-OCT-13'), 1, 17, 8 from dual union all
select '0178', 'Saxon, Victoria' , to_date ('16-OCT-13'), 2, 748, 4 from dual union all
select '0178', 'Saxon, Victoria' , to_date ('16-OCT-13'), 2, 748, 5 from dual
)
-- End of simulated inputs (for testing purposes only, not part of the solution).
-- SQL query begins BELOW THIS LINE.
select subject_number patient, mdt_date, pres_phys, cr_mdt_phys,
listagg(recomm, ',') within group (order by recomm) as recommendations
from test_data
group by subject_number, patient, mdt_date, pres_phys, cr_mdt_phys
order by subject_number, patient, mdt_date, pres_phys, cr_mdt_phys -- If needed
;
PATIENT MDT_DATE PRES_PHYS CR_MDT_PHYS RECOMMENDATIONS
------- --------- --------- ----------- ---------------
0177 24-OCT-13 1 17 1,2,8
0178 16-OCT-13 2 748 4,5
Oracle或sql server? –
爲什麼使用pl/sql?還是你的意思是使用Oracle SQL?這裏不需要pl/sql。另外,Apex Interactive Report有什麼特別之處?我假設「沒有」,但請澄清。 – mathguy
你能提供一個帶有列名的表數據的例子嗎?您是否想要將交叉報告中的一行中的一列的結果合併到一列中? –