我正在使用group by
子句,我也想使用order by
。任何人都可以告诉我如何在以下查询中实现order by
子句
SELECT
MIN(UR.REG_UNIQUE_ID) "ANUBANDH ID",
MIN(UR.FIRM_NAME) "FIRM OF CONTRACTOR",
MIN(UR.NAME) "NAME OF PROPRIETOR",
MIN(CD.MOBILE)"MOBILE NUMBER",
MIN(CD.EMAIL) EMAIL,
MIN(UR.ADDRESS)|| ' ' || MIN(UR.ADDRESS2) ADDRESS,
MIN(UR.COR_ADDRESS1) || '' || MIN(UR.COR_ADDRESS2) AS "CORRESPONDING ADDRESS",
MIN(CASE
WHEN MS.OIT_STATUS=1 THEN 'YES'
ELSE 'NO'
END) "OYT ELIGIBILITY",
LISTAGG(UUC.NAME, ', ') WITHIN GROUP (ORDER BY RC.CIRCLE_RATE_ID ASC) "CIRCLE"
--MIN(UUC.NAME)
FROM CONTRACTOR_DETAIL CD
JOIN USER_REGISTRATION UR
ON CD.CONTRACTOR_ID=UR.CONTRACTOR_ID
JOIN MANAGE_SERVICES MS
ON MS.CONTRACTOR_ID=UR.CONTRACTOR_ID
JOIN RC_CONTRACTOR RC
ON RC.CONTRACTOR_ID=UR.CONTRACTOR_ID
JOIN CIRCLE_RATE CR
ON CR.CIRCLE_RATE_ID = RC.CIRCLE_RATE_ID
JOIN UAM_USER.CIRCLE UUC
ON CR.CIRCLE_ID=UUC.CIRCLE_ID
WHERE UR.REG_UNIQUE_ID IS NOT NULL
AND UR.PAYMENT_STATUS=1
AND MS.REG_CLASS_ID IN (5,6,7)
GROUP BY UR.CONTRACTOR_ID;
答案 0 :(得分:1)
只需在group by子句后的最后一个查询中放置order by子句
SELECT
MIN(UR.REG_UNIQUE_ID) "ANUBANDH ID",
MIN(UR.FIRM_NAME) "FIRM OF CONTRACTOR",
MIN(UR.NAME) "NAME OF PROPRIETOR",
MIN(CD.MOBILE)"MOBILE NUMBER",
MIN(CD.EMAIL) EMAIL,
MIN(UR.ADDRESS)|| ' ' || MIN(UR.ADDRESS2) ADDRESS,
MIN(UR.COR_ADDRESS1) || '' || MIN(UR.COR_ADDRESS2) AS "CORRESPONDING
ADDRESS",
MIN(CASE
WHEN MS.OIT_STATUS=1 THEN 'YES'
ELSE 'NO'
END) "OYT ELIGIBILITY",
LISTAGG(UUC.NAME, ', ') WITHIN GROUP (ORDER BY RC.CIRCLE_RATE_ID ASC)
"CIRCLE"
--MIN(UUC.NAME)
FROM CONTRACTOR_DETAIL CD
JOIN USER_REGISTRATION UR
ON CD.CONTRACTOR_ID=UR.CONTRACTOR_ID
JOIN MANAGE_SERVICES MS
ON MS.CONTRACTOR_ID=UR.CONTRACTOR_ID
JOIN RC_CONTRACTOR RC
ON RC.CONTRACTOR_ID=UR.CONTRACTOR_ID
JOIN CIRCLE_RATE CR
ON CR.CIRCLE_RATE_ID = RC.CIRCLE_RATE_ID
JOIN UAM_USER.CIRCLE UUC
ON CR.CIRCLE_ID=UUC.CIRCLE_ID
WHERE UR.REG_UNIQUE_ID IS NOT NULL
AND UR.PAYMENT_STATUS=1
AND MS.REG_CLASS_ID IN (5,6,7)
GROUP BY UR.CONTRACTOR_ID
ORDER BY MIN(UR.REG_UNIQUE_ID);