[英]Oracle query optimisation without sub-query
提示 #1:圖像不利於用您的數據構建測試用例:-(
但是你可以做這樣的事情,假設“0”是一個合適的邊界(或者可能是-1)
SQL> with t as (
2 select 77 t_id, 'N' msg, 220 score from dual union all
3 select 77 t_id, 'C' msg, 220 score from dual union all
4 select 1 t_id, 'N' msg, 120 score from dual union all
5 select 1 t_id, 'N' msg, 102 score from dual union all
6 select 2 t_id, 'N' msg, 112 score from dual union all
7 select 2 t_id, 'C' msg, 152 score from dual union all
8 select 3 t_id, 'N' msg, 172 score from dual union all
9 select 3 t_id, 'N' msg, 192 score from dual union all
10 select 4 t_id, 'N' msg, 100 score from dual union all
11 select 5 t_id, 'N' msg, 101 score from dual
12 )
13 select t_id, max(score)
14 from t
15 group by t_id
16 having min(decode(msg,'C',0,score)) > 0;
T_ID MAX(SCORE)
---------- ----------
1 120
4 100
5 101
3 192
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.