我有一个表,像这样的数据:
ID, END_DATE, CLOSE_DATE 1, 2018-05-18, 2018-05-15 2, 2018-05-18, 2018-05-14 3, 2018-05-18, 2018-05-11 4, 2018-05-18, 2018-05-10
在Oracle服务器中查询时需要输出
END_DATE CLOSE_DATE ID 2018-05-18 [2018-05-15,2018-05-14,2018-05-11,2018-05-10] [1,2,3,4]
我尝试使用listagg,但它适用于Id或Close Date,但不能同时适用于两者。
select (listagg(CLOSE_DATE,',') within group (order by CLOSE_DATE DESC)) CLOSE_DATE , END_DATE from TBL_S_PLCLOSEDATE where D_END='18-MAY-2018'
请让我知道如何在Oracle服务器中编写相同的sql。
你有试过吗?
select end_date, listagg(CLOSE_DATE, ',') within group (order by CLOSE_DATE DESC) as close_dates, listagg(id, ',') within group (order by id) as ids from TBL_S_PLCLOSEDATE where D_END = date '2018-05-18' group by end_date;