以下语句为我提供了每天的平均风速和总产量,按站点 ID 和工厂编号分组。
SELECT STE_ID, PNT_NO, T_SMP, AVG(AVR_WS), SUM(AVR_PW) FROM argosrecord GROUP BY STE_ID , PNT_NO , YEAR(T_SMP) , MONTH(T_SMP) , DAY(T_SMP)
我想调整这个查询来计算从凌晨 2 点到凌晨 2 点而不是午夜到午夜的平均值和总和。
select STE_ID,
PNT_NO,
YEAR(dateadd(hour, -2, T_SMP)) as Year,
MONTH(dateadd(hour, -2, T_SMP)) as Month,
DAY(dateadd(hour, -2, T_SMP)) as Day,
AVG(AVR_WS) as AVG_AVR_WS,
SUM(AVR_PW) as SUM_AVR_PW
from argosrecord
group by STE_ID,
PNT_NO,
YEAR(dateadd(hour, -2, T_SMP)),
MONTH(dateadd(hour, -2, T_SMP)),
DAY(dateadd(hour, -2, T_SMP))
对于那些使用 MySQL 的人:
select
STE_ID,
PNT_NO,
T_SMP,
avg(AVR_WS),
sum(AVR_PW)
FROM
argosrecord
GROUP BY
STE_ID ,
PNT_NO ,
YEAR(DATE_ADD(T_SMP, INTERVAL -2 HOUR)) ,
MONTH(DATE_ADD(T_SMP, INTERVAL -2 HOUR)) ,
DAY(DATE_ADD(T_SMP, INTERVAL -2 HOUR))