試圖讓這個輸出Oracle 8i中:最小值最大值與標識 - 甲骨文
column1 |time
________|_______
ABC | 00:00:01
END | 00:00:03
123 | 00:00:04
END | 00:00:07
ABC | 00:00:08
END | 00:00:10
與來自另一個查詢
column1 |time |ID
________|___________|
ABC | 00:00:01 | 1
ABC | 00:00:02 | 1
ABC | 00:00:03 | 1
123 | 00:00:04 | 1
123 | 00:00:05 | 1
123 | 00:00:06 | 1
123 | 00:00:07 | 1
ABC | 00:00:08 | 2
ABC | 00:00:09 | 2
ABC | 00:00:10 | 2
此查詢獲取的最小值和最大值,而不考慮ID此輸出。
select (case when n.n = 1 then column1 else 'END' end) as column1,
(case when n.n = 1 then firsttime else lasttime end) as "time"
from (select column1, min(time) as firsttime, max(time) as lasttime
from t
group by column1
) t cross join
(select 1 as n from dual union all select 2 from dual) n
order by column1, n.n;
如何做同樣的事情,而不是獲得第一列和第一列的出現值,考慮ID以及?
取代'GROUP BY column1'通過'GROUP BY列1,id'? –
我想你想要't.firsttime,t.column1,n.n'的命令以及將相鄰值保持在一起? –