【发布时间】:2019-09-04 16:06:57
【问题描述】:
我有两列“日期”和“温度”。我想选择两个特定日期之间的平均温度,例如4 月 1 日至 7 日按年份分组。 当我使用这个查询时
select avg(temperature) from table where dayofyear(date) between 91 and 97 group by year(date)
出现两个问题。
- 在闰年中,2 月 28 日之后的每一天都有不同的值
- 当我想选择平均值时,例如在 12 月 30 日至 1 月 5 日期间,此查询:
select avg(temperature) from table where dayofyear(date) between 364 and 5 group by year(date)返回“null”。
与第 2 点对应的是另一个问题。如何在例如之间接收数据12 月 30 日(一年前)和 1 月 5 日按年份分组?
【问题讨论】: