我想在Status1
每个序列的列中获取相同值的第一个和最后一个值!
这是我的表的一个例子:
time Status1 Eficiencia Lote
----------------------------------------------------
2020 06 14 18:03:48.457 70 80 95
2020 06 14 18:04:47.693 70 80 95
2020 06 14 18:06:58.203 55 80 95
2020 06 14 18:08:19.900 55 80 95
2020 06 14 18:09:45.537 55 80 95
2020 06 14 18:10:06.670 100 80 13
2020 06 14 18:10:27.297 100 80 13
2020 06 14 18:10:31.810 100 80 13
2020 06 14 18:10:43.187 100 80 13
2020 06 14 18:11:30.303 55 80 14
2020 06 14 18:12:07.563 55 80 14
2020 06 14 18:18:54.997 55 80 14
我试过这个,但使用这个我没有得到每个序列,而是在洞表中!
;with cte as
(
select
*,
RnAsc = row_number() over (partition by [Status1] order by time),
RnDesc = row_number() over (partition by [Status1] order by time desc)
from
[VALORES_DB].[dbo].[OEE_TESTE]
)
select time, [Status1], Eficiencia, Lote, Status1
from cte
where RnAsc = 1 or RnDesc = 1
我想得到以下信息:
time Status1 Eficiencia Lote
------------------------------------------------------
2020 06 14 18:03:48.457 70 80 95
2020 06 14 18:04:47.693 70 80 95
2020 06 14 18:06:58.203 55 80 95
2020 06 14 18:09:45.537 55 80 95
2020 06 14 18:10:06.670 100 80 13
2020 06 14 18:10:43.187 100 80 13
2020 06 14 18:11:30.303 55 80 14
2020 06 14 18:18:54.997 55 80 14