0

我想在这个查询上设置一个时间约束,但是我所有的尝试都失败了:(我想要从这个日期2013-06-21 13:15:00.000到的时间约束2013-06-28 13:15:00.000。这些时间在一个名为trendLog15Min的列中的表中UTCTimeStamp

这是我想要时间约束的查询:

SELECT a.UTCTimeStamp, CASE WHEN a.ElapsedValue = b.ElapsedValue THEN 1 ELSE 0 END AS ConstantData
FROM tblLive_trendLog_15Min a,tblLive_trendLog_15Min b
WHERE a.UTCTimeStamp = dateadd(minute, -15, b.UTCTimeStamp)

太感谢了。

4

1 回答 1

1

您是否只是想添加WHERE标准:

SELECT a.UTCTimeStamp, CASE WHEN a.ElapsedValue = b.ElapsedValue THEN 1 ELSE 0 END AS ConstantData 
FROM tblLive_trendLog_15Min a
    JOIN tblLive_trendLog_15Min b 
        ON a.UTCTimeStamp = dateadd(minute, -15, b.UTCTimeStamp)
WHERE a.UTCTimeStamp >= '2013-06-21 13:15:00.000' 
    AND a.UTCTimeStamp <= '2013-06-28 13:15:00.000'

请注意,我将您的查询更改为使用INNER JOIN.

您还可以使用BETWEEN(尽管我更喜欢大于/小于使用日期时):

WHERE a.UTCTimeStamp BETWEEN '2013-06-21 13:15:00.000' AND '2013-06-28 13:15:00.000'
于 2013-06-27T23:02:46.983 回答