简体   繁体   English

SQL。 从时间戳范围中选择最大值

[英]SQL . Selecting highest value from a range of timestamp

I have a code like this. 我有这样的代码。 My intended result is to grab the highest value from a set range of timestamps. 我的预期结果是从设定的时间戳范围中获取最高的价值。 I'm not sure why this isn't working. 我不确定为什么这行不通。 I am using Oracles SQL 10. Thank you in advance for your help. 我正在使用Oracles SQL10。在此先感谢您的帮助。

Code

 SELECT value, timestamp
      FROM farm1 f
     WHERE timestamp between 1405987200 and (1405987200 + 86400)
     where value =
           (select max(x.value)
             from farm1 x
             where x.timestamp between 1405987200 and (1405987200 + 86400);

Expected Results 预期成绩

 TIMESTAMP        VALUE
----------    ----------

1406056898         8.09

Results it is producing 它产生的结果

 TIMESTAMP        VALUE
----------    ----------
1405992437         6.49
1406056898         8.09
1406055371         9.4
1406071600         1.12

In addition is there a way to grab today's timestamps only without using unix time such as 1405992437 ? 另外,有没有一种方法可以仅使用1405,0002437之类的unix时间来获取今天的时间戳?

SELECT MAX(value)
FROM farm1
WHERE timestamp BETWEEN 1405987200 AND (1405987200 + 86400)

?

And for your second question, do you mean using human readable comparisons? 关于第二个问题,您的意思是使用人类可读的比较吗? You can always use WHERE TO_DATE(timestamp,...) but I'm not sure about how your indexes would react after that. 您始终可以使用WHERE TO_DATE(timestamp,...)但是我不确定在那之后您的索引会如何反应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM