SELECT
TRANSACTION_ID,
(SELECT CASE WHEN CLOSE_DATE = NULL
THEN
round(sysdate - created_date)
ELSE ROUND(CLOSE_DATE - CREATED_DATE)
) as NODAYS
FROM TBL_TRANSACTION
WHERE CREATED_BY = 101913
答案 0 :(得分:1)
你有一个额外的select
,你错过了end
,你无法用等号运算符测试null
- null
永远不等于,或者不等于,任何东西,甚至是它自己。
这会让你更进一步:
SELECT
TRANSACTION_ID,
CASE
WHEN CLOSE_DATE IS NULL
THEN round(sysdate - created_date)
ELSE ROUND(CLOSE_DATE - CREATED_DATE)
END as NODAYS
FROM TBL_TRANSACTION
WHERE CREATED_BY = 101913
您可以使用NVL()
来简化这一点:
SELECT TRANSACTION_ID,
ROUND(NVL(CLOSE_DATE, SYSDATE) - CREATED_DATE) as NODAYS
FROM TBL_TRANSACTION
WHERE CREATED_BY = 101913