Postgresql:嵌套查询以检查一组两列的最后一条记录是否早于 30 分钟

Posrgresql: Need query to check if last record for a group of two columns is older than 30 mins or not

下面是我写的:

select column1, column2 
where time::time between "07:00:00: and "17:00:00: and time - now() > "-00:30:00" 
group by column1, column2;

如果我 运行 每 30 分钟查询一次,它会为我获取所需的输出吗?

我想你想要一个 having 子句:

select col1, col1
from mytable 
group by col1, col2
having max(time) >= now() - interval '30 minutes'

这 returns 所有 (col1, col2) 个最新 time 不到 30 分钟前的元组。