我有一个类似于的表
it.name | ReqTime |
---|---|
1-跃点:IP | 5 |
2-跃点:IP | 1 |
3-跃点:IP | 22 |
4-跃点:IP | 15 |
5-跃点:IP | 30 |
6-跃点:IP | 30 |
您可以尝试使用LEAD
窗口函数。
SELECT *
FROM (
select it.name as target_app,
LEAD(it.name) OVER(ORDER BY it.name) the_2nd_hop
hsu.value as req_rate
from items it
inner join hosts hs on hs.hostid = it.hostid
inner join history hsu on hsu.itemid = it.itemid
where it.name like '% - Hop%' and to_timestamp(hsu.clock) BETWEEN NOW() - INTERVAL '1 MINUTES' AND NOW()
) t1
WHERE the_2nd_hop IS NOT NULL
order by target_app