fix:修改了聚合查询
This commit is contained in:
parent
09c9a078c4
commit
785a02bf8a
@ -64,12 +64,7 @@ func (dao *SensorDAO) GetAggregatedData(start, end time.Time, interval string) (
|
||||
// 构建通用查询
|
||||
query := `
|
||||
SELECT
|
||||
DATE_FORMAT(
|
||||
FROM_UNIXTIME(
|
||||
FLOOR(UNIX_TIMESTAMP(timestamp)/?)*?
|
||||
),
|
||||
?
|
||||
) as ts,
|
||||
MIN(timestamp) as ts,
|
||||
ROUND(AVG(temperature)/10, 1) as avg_temp,
|
||||
MAX(rainfall) - MIN(rainfall) as rainfall,
|
||||
ROUND(AVG(humidity)/10, 1) as avg_humidity,
|
||||
@ -83,8 +78,6 @@ func (dao *SensorDAO) GetAggregatedData(start, end time.Time, interval string) (
|
||||
// 执行查询
|
||||
rows, err := dao.db.Query(
|
||||
query,
|
||||
intervalSeconds, intervalSeconds, // 用于FROM_UNIXTIME参数
|
||||
timeFormat, // DATE_FORMAT格式
|
||||
start, end, // 时间范围
|
||||
intervalSeconds, // GROUP BY参数
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user