SELECT 所有历史记录中温度的 MAX MIN 值 CURRENT DAY 但去年
SELECT MAX MIN value of temperature CURRENT DAY but last YEARS from ALL history
我想请你帮忙 SQL。
我有数据库,其中有 4 列。 (时间、温度、嗡嗡声、压力)
在这个 table 中是来自我的气象站的数据。
现在 table 中有 110000 行包含过去 3 年的记录。
我想像今天一样在同一天获得所有过去几年的温度的最大值和最小值。
我知道如何在同一天获取去年的所有临时数据,但我不知道接下来会发生什么:-D
SELECT temp
FROM `table_name`
WHERE (
YEAR(time) < YEAR(CURDATE())
AND MONTH(time) = MONTH(CURDATE())
AND DAY(time) = DAY(CURDATE())
)
抱歉我的英语不好。
谢谢
您可以使用日期算法和聚合:
select min(temp) min_temp, max(temp) max_temp
from table_name
where
year(time) < year(current_date)
and month(time) = month(current_date)
and day(time) = day(current_date)
如果您想要按年份显示的结果:
select year(time) yr, min(temp) min_temp, max(temp) max_temp
from table_name
where
year(time) < year(current_date)
and month(time) = month(current_date)
and day(time) = day(current_date)
group by year(time)
order by year(time)
我想请你帮忙 SQL。 我有数据库,其中有 4 列。 (时间、温度、嗡嗡声、压力) 在这个 table 中是来自我的气象站的数据。 现在 table 中有 110000 行包含过去 3 年的记录。 我想像今天一样在同一天获得所有过去几年的温度的最大值和最小值。
我知道如何在同一天获取去年的所有临时数据,但我不知道接下来会发生什么:-D
SELECT temp
FROM `table_name`
WHERE (
YEAR(time) < YEAR(CURDATE())
AND MONTH(time) = MONTH(CURDATE())
AND DAY(time) = DAY(CURDATE())
)
抱歉我的英语不好。
谢谢
您可以使用日期算法和聚合:
select min(temp) min_temp, max(temp) max_temp
from table_name
where
year(time) < year(current_date)
and month(time) = month(current_date)
and day(time) = day(current_date)
如果您想要按年份显示的结果:
select year(time) yr, min(temp) min_temp, max(temp) max_temp
from table_name
where
year(time) < year(current_date)
and month(time) = month(current_date)
and day(time) = day(current_date)
group by year(time)
order by year(time)