你真的需要使用功能的表連接,並使用分析的在PL/SQL的上下文切換和案例讓你一個1或0 ...
Case when sum(T1.Attempts) over (partition by T1.ID2) < T2."value" then 0 else 1 end
;
with Table1 (ID1, ID2, Attempts) as (
SELECT 01, 01, 3 FROM DUAL UNION ALL
SELECT 02, 01, 2 FROM DUAL UNION ALL
SELECT 03, 01, 0 FROM DUAL UNION ALL
SELECT 04, 01, 4 FROM DUAL UNION ALL
SELECT 05, 02, 1 FROM DUAL UNION ALL
SELECT 06, 02, 2 FROM DUAL UNION ALL
SELECT 07, 03, 20 FROM DUAL ),
Table2 (ID, Description, "value") as (
SELECT 01, 'Blah', 23 FROM DUAL UNION ALL
SELECT 02, 'BlahBlah', 12 FROM DUAL UNION ALL
SELECT 03, 'Table1 Max Val', 20 FROM DUAL)
SELECT Case when sum(T1.Attempts) over (partition by T1.ID2) < T2."value" then 0 else 1 end as MyResult
FROM Table1 T1
INNER JOIN table2 T2
on T1.ID2 = T2.ID
WHERE T2.Description = 'Blah'
簡單地通過一個where子句參數的ID和限制結果成爲myResult列..
但也許我不明白這個問題。
,或者返回一個值/記錄:
with Table1 (ID1, ID2, Attempts) as (
SELECT 01, 01, 3 FROM DUAL UNION ALL
SELECT 02, 01, 2 FROM DUAL UNION ALL
SELECT 03, 01, 0 FROM DUAL UNION ALL
SELECT 04, 01, 4 FROM DUAL UNION ALL
SELECT 05, 02, 1 FROM DUAL UNION ALL
SELECT 06, 02, 2 FROM DUAL UNION ALL
SELECT 07, 03, 20 FROM DUAL ),
Table2 (ID, Description, "value") as (
SELECT 01, 'Blah', 23 FROM DUAL UNION ALL
SELECT 02, 'BlahBlah', 12 FROM DUAL UNION ALL
SELECT 03, 'Table1 Max Val', 20 FROM DUAL)
SELECT DISTINCT Case when sum(T1.Attempts) over (partition by T1.ID2) < T2."value" then 0 else 1 end as MyResult
FROM Table1 T1
INNER JOIN table2 T2
on T1.ID2 = T2.ID
WHERE T2.Description = 'Blah'
其中是函數的返回數據類型? –
也添加你得到的錯誤 –
我添加了函數的返回類型(看原帖) –