【问题标题】:How to get the values in between a particular range timestamps [closed]如何获取特定范围时间戳之间的值[关闭]
【发布时间】:2012-10-07 09:53:33
【问题描述】:

我在 SQL Server 2008 中有一个名为 ,timestamplog which contains one column of name LogTime of typeINTEGER 的表`

数值是这样的:

1350468610,
1350468000,
1350381600,
1350295810

我需要介于 13504686091350468001.. 之间的值。

请告诉我如何查询这些值。

我尝试了以下查询

select LogTime 
from timestamplog 
where LogTime between 1350468609 and 1350468001

select LogTime 
from timestamplog 
where LogTime >= '1350468610' and  LogTime <= '1350468000'

select LogTime 
from timestamplog 
where LogTime >= convert(decimal, 1350468610) and LogTime <= convert(decimal,1350468000)

select LogTime 
from timestamplog 
where LogTime >= convert(varchar, 12) and LogTime <= convert(varchar, 14)

但是行不来了……

实际上表中的值是在表TIMELOG中存储为INTEGER的时间戳值

IMP 注意:假设如果像 12,13,14 这样的值进入表,上述查询工作正常。但是当我比较长度为 10 的数字时,查询不会检索到任何值

感谢提前

【问题讨论】:

    标签: sql-server range between timestamp datetime2


    【解决方案1】:

    因为 1350468001 小于 1350468609,如果您颠倒顺序,您的任何查询都将起作用。我会去...

    select LogTime from timestamplog where LogTime between 1350468001 and 1350468609
    

    这是一个包含范围。

    【讨论】:

    • 当然是+1! :-) 查询是正确的 - 但是 BETWEEN 值被翻转了 :-) 很好!
    • 以上查询无效
    • 那么您可能没有该范围内的值。你猜对了吗?
    • @user1716577 “不工作”对任何人都没有帮助。它会产生错误吗? (如果是这样,什么错误?)。它是否会产生错误的结果(如果是,如何错误?太多,太少,为什么应该/不应该包含某些结果?)导致您的机器爆炸? (不确定我们是否可以提供帮助)
    • 那么就没有数据了。你能找到一个你认为应该显示的数字吗?
    猜你喜欢
    • 1970-01-01
    • 2012-08-25
    • 1970-01-01
    • 1970-01-01
    • 2020-11-30
    • 1970-01-01
    • 2018-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多