select TTIME as maxper
from (
SELECT TTIME,
row_number() over (order by TTIME desc) as rn,
count(*) over () as total_count
FROM <mytable>
WHERE alarm = 0
) t
where rn = 1
or rn = total_count
ORDER BY TTIME DESC;
此查询返回以下(时间戳)
27.01.2021, 13:52:00.000
18.01.2021, 00:00:00.000
是否有一种简单的方法可以通过将结果放入变量中来转换结果,以便在像这里这样的存储过程中使用?
SELECT <something>
FROM <stored procedure>(1, 1, null, '19.01.2021 00:00', '26.01.2021 09:00', null) p;
用变量 maxper
代替 '19.01.2021 00:00', '26.01.2021 09:00'