В основном я хочу иметь возможность классифицировать выбранный столбец в другой диапазон, например, так: если диапазон> 0 возвращает значение столбца.если диапазон <0, возвращается «Истек».Вот код: </p>
SELECT
PACKAGE_ID,
PACKAGE_NAME,
ORG_ID,
ORG_NAME,
VALID_FROM,
VALID_TO,
DAYS_LEFT,
TOTAL,
BALANCE,
THRESHOLD,
REPORTID
FROM
( SELECT
B.ORG_ID,
B.ORG_NAME,
A.PACKAGE_ID,
A.NAME AS PACKAGE_NAME,
A.BALANCE AS BALANCE,
A.VALID_FROM,
A.VALID_TO,
C.REPORT_CODE,
Floor(A.VALID_TO - (SELECT current_date FROM dual)) AS DAYS_LEFT,
X.TOTAL AS TOTAL,
CASE X.TOTAL WHEN 0 THEN 0 ELSE A.BALANCE / X.TOTAL* 100 END AS THRESHOLD,
'MIS0014' AS REPORTID
FROM
PREPAID_PACKAGE A
JOIN MST_ORGANISATION B ON B.ORG_ID = A.ORG_ID
JOIN PREPAID_REPORT C ON C.PACKAGE_ID = A.PACKAGE_ID
JOIN (
SELECT
SUM(Z.TOPUP_VALUE) as TOTAL,
Y.ORG_ID AS ORG_ID,
Y.PACKAGE_ID AS PACKAGE_ID
from PREPAID_VALUE Z
JOIN PREPAID_PACKAGE Y on Y.PACKAGE_ID =Z.PACKAGE_ID
GROUP BY Y.ORG_ID, Y.PACKAGE_ID
) X ON X.ORG_ID=A.ORG_ID AND X.PACKAGE_ID=A.PACKAGE_ID
ORDER BY
ORG_CODE,
PACKAGE_ID,
PACKAGE_NAME,
C.REPORT_CODE) S
WHERE
REPORTID='MIS0014'
AND ORG_ID = 1
AND VALID_FROM >= TO_DATE('01/02/2007', 'dd/mm/yyyy')
AND VALID_TO < TO_DATE('01/02/2013', 'dd/mm/yyyy')
AND THRESHOLD < 20
AND DAYS_LEFT < 13
GROUP BY
PACKAGE_ID,
PACKAGE_NAME,
ORG_ID,
ORG_NAME,
DAYS_LEFT,
VALID_FROM,
VALID_TO,
REPORTID,
TOTAL,
BALANCE,
THRESHOLD,
REPORTID
Я хотел бы изменить следующее утверждение:
Floor(A.VALID_TO - (SELECT current_date FROM dual)) AS DAYS_LEFT,
на следующее:
when Floor(A.VALID_TO - (SELECT current_date FROM dual)) > 0 then Floor(A.VALID_TO - (SELECT current_date FROM dual)) else 'Expired' end AS DAYS_LEFT,
или что-то подобное,Есть ли ключевое слово / функция, позволяющая мне это сделать?