使用两个列值进行查询以创建范围 [英] Query using two column values to create range

查看:86
本文介绍了使用两个列值进行查询以创建范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,其中包含一个开始时间时间戳列和一个代表分钟的长度整数列。我希望能够执行以下操作:

I have a table with a start time timestamp column and a length integer column representing minutes. I want to be able to do something like this:

SELECT * FROM table t 
    WHERE t.start_time + interval 't.length minutes' < '2011-10-21';

但这是行不通的。有什么办法可以从两个列的值中获取新的时间戳吗?

But this doesn't work. Is there any way to get a new timestamp from the two column values?

我正在运行PostgreSQL的8.3版本

I'm running version 8.3 of postgresql

推荐答案

SELECT *
FROM   table 
WHERE  (start_time + interval '1 min' * length_minutes) < '2011-10-21 0:0'::timestamp;



注释




  • 将您的整数乘以1分钟即可,并将其添加到时间戳

  • 时间戳时间戳进行比较要快一些。 日期必须强制转换为时间戳(自动)。

  • Notes

    • Simply multiply your integer with 1-minute intervals and add it to the timestamp.
    • It is slightly faster to compare the timestamp to a timestamp. A date would have to be cast to timestamp (automatically).
    • 这篇关于使用两个列值进行查询以创建范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆