我在 BigQuery 中有此查询
SELECT Id,
AVG(VeryActiveMinutes) AS avg_very_active,
SUM(VeryActiveMinutes) AS total_very_active,
SUM(SedentaryMinutes) AS total_sedentary
FROM `fit-mantra-410702.fitbit_data.dailyactivity`
GROUP BY Id
ORDER BY avg_very_active DESC
avg_very_active 返回的值例如 87.333333333333329。
我尝试在 AVG() 内外使用 CAST() 来减少到只有 2 位小数,但没有成功。我该如何解决这个问题?
使用
ROUND(...,2)
将聚合结果返回到小数点后 2 位。
SELECT Id,
ROUND(AVG(VeryActiveMinutes),2) AS avg_very_active,
SUM(VeryActiveMinutes) AS total_very_active,
SUM(SedentaryMinutes) AS total_sedentary
FROM `fit-mantra-410702.fitbit_data.dailyactivity`
GROUP BY Id
ORDER BY avg_very_active DESC