DB2 时间戳选择语句 [英] DB2 Timestamp select statement

查看:35
本文介绍了DB2 时间戳选择语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个简单的查询,该查询根据时间戳获取数据,如下所示:

I am trying to run a simple query which gets me data based on timestamp, as follows:

SELECT * 
FROM <table_name> 
WHERE id = 1 
AND usagetime = timestamp('2012-09-03 08:03:06') 
WITH UR;

这似乎没有向我返回记录,而该记录存在于 id = 1 的数据库中.

This does not seem to return a record to me, whereas this record is present in the database for id = 1.

我在这里做错了什么?

usagetime列的数据类型正确,设置为timestamp.

The datatype of the column usagetime is correct, set to timestamp.

推荐答案

@bhamby 是正确的.通过保留时间戳值的微秒,您的查询将仅匹配 2012-09-03 08:03:06.000000 的使用时间

@bhamby is correct. By leaving the microseconds off of your timestamp value, your query would only match on a usagetime of 2012-09-03 08:03:06.000000

如果您没有从之前的查询中捕获完整的时间戳值,您可以指定一个范围谓词,该谓词将匹配该时间的任何微秒值:

If you don't have the complete timestamp value captured from a previous query, you can specify a ranged predicate that will match on any microsecond value for that time:

...WHERE id = 1 AND usagetime BETWEEN '2012-09-03 08:03:06' AND '2012-09-03 08:03:07'

...WHERE id = 1 AND usagetime >= '2012-09-03 08:03:06' 
   AND usagetime < '2012-09-03 08:03:07'

这篇关于DB2 时间戳选择语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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