需要在列表标签中找到最小和最大日期 像这样在一列 Min Date:01/01/2015 / Max Date:01/05/2015
SELECT D.ITEM_ID AS "ItemId",
C.NAME AS "ItemName",
D.UOM_ID AS "UomId",
B.DESCRIPTION AS "Uom",
sum(D.REQUIRED_QTY) AS "Quantity",
LISTAGG(A.REASON, ', ') WITHIN GROUP (ORDER BY A.REASON) "ReasonType",
LISTAGG(D.REQUIRED_DATE, ', ') WITHIN GROUP (ORDER BY D.REQUIRED_DATE) "PoRequiredDate",
LISTAGG(D.PO_COMMENT, ', ') WITHIN GROUP (ORDER BY D.PO_COMMENT) "Comment"
FROM BIZZXE_V2_SCH.REASONS A,
BIZZXE_V2_SCH.UOMS B,
BIZZXE_V2_SCH.ITEMS C,
BIZZXE_V2_SCH.PO_REQUEST_ITEMS D,
BIZZXE_V2_SCH.PO_REQUESTS E
WHERE E.PO_REQUEST_ID=D.PO_REQUEST_ID
AND D.ITEM_ID=C.ITEM_ID
AND D.UOM_ID=B.UOM_ID
AND D.REASON_ID=A.REASON_ID
GROUP BY D.ITEM_ID, C.NAME, D.UOM_ID, B.DESCRIPTION
需要将 Min dt 和 Max dt 作为“PoRequiredDate”添加到一列
WITH DATA AS(
SELECT listagg(REQUIRED_DATE, ',') WITHIN GROUP (ORDER BY REQUIRED_DATE) dt
FROM PO_REQUEST_ITEMS
WHERE PO_REQUEST_ID =16
)
SELECT dt,
SUBSTR(dt, 1, instr(dt, ',', 1, 1)-1) min_dt,
SUBSTR(dt, instr(dt, ',', -1, 1)+1) max_dt
FROM data
/