【问题标题】:postgreSQL - Daily averages from hourly values by unixtimepostgreSQL - unixtime 每小时值的每日平均值
【发布时间】:2021-07-05 10:05:35
【问题描述】:

我是一般数据库的新手,我使用的是 postgreSQL(通过 pgAdmin 4),我需要从具有 unixtime 格式的日期的小时表,如下所示: one of my tables

我想要以标准日期格式(使用“to_timestamp()”获得的格式,如:2020-07-17)以通常的日期升序来确定温度和湿度的每日平均值。

感谢您的关注。

【问题讨论】:

  • 为了给我们一些工作,你能提供一个sqlfiddle.com/#!17的数据吗?
  • 很抱歉,我已经想出了解决方案,但我忘了删除问题,还是谢谢你。
  • 完全没有问题,@francesco。只是不要忘记删除问题,或者更好!与我们分享解决方案。好好的。

标签: postgresql average unix-timestamp


【解决方案1】:

好的,这很简单,这是我的具体情况的解决方案:

select date_trunc( 'day' , to_timestamp("dateTime")) , avg(air_temperature) as "avg_T" , avg(relative_humidity) as "avg_RH" , avg(wind_speed) as "avg_WindSpeed"
from table
group by date_trunc( 'day' , to_timestamp("dateTime"))
order by date_trunc( 'day' , to_timestamp("dateTime")) asc

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-24
    • 2017-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-09
    相关资源
    最近更新 更多