вот под оракл:
sqlfiddle.com/#!4/1a2436/1CREATE TABLE T1
("IID" int, "DDT" date)
;
INSERT ALL
INTO T1 ("IID", "DDT")
VALUES (2, to_date('2003-05-03 12:12', 'yyyy-mm-dd hh24:mi'))
INTO T1 ("IID", "DDT")
VALUES (1, to_date('2003-05-03 12:22', 'yyyy-mm-dd hh24:mi'))
INTO T1 ("IID", "DDT")
VALUES (1, to_date('2003-05-03 12:32', 'yyyy-mm-dd hh24:mi'))
INTO T1 ("IID", "DDT")
VALUES (2, to_date('2003-05-03 12:42', 'yyyy-mm-dd hh24:mi'))
INTO T1 ("IID", "DDT")
VALUES (1, to_date('2003-05-03 12:52', 'yyyy-mm-dd hh24:mi'))
INTO T1 ("IID", "DDT")
VALUES (2, to_date('2003-05-03 13:13', 'yyyy-mm-dd hh24:mi'))
INTO T1 ("IID", "DDT")
VALUES (2, to_date('2003-05-03 13:14', 'yyyy-mm-dd hh24:mi'))
INTO T1 ("IID", "DDT")
VALUES (1, to_date('2003-05-03 13:21', 'yyyy-mm-dd hh24:mi'))
INTO T1 ("IID", "DDT")
VALUES (2, to_date('2003-05-03 14:24', 'yyyy-mm-dd hh24:mi'))
SELECT * FROM dual
;
SELECT IID, MAX(ids) AS max_id
FROM (
SELECT IID ,
COUNT(*) OVER (PARTITION BY IID
ORDER BY DDT
RANGE INTERVAL '60' MINUTE PRECEDING) AS ids
FROM T1
)
GROUP BY IID;
stackoverflow.com/questions/14434032/get-the-maxim...