[英]Sum different values from same column
I need to sum all the temperatures for all stations by hour: 我需要按小时计算所有站点的所有温度:
station hour temperature
-----------------------------------
100 1 2
101 1 2
100 2 4
101 2 4
I want the result to be like this: 我希望结果是这样的:
hour temperature
---------------------
1 4
2 8
... where the temperature for station 100 gets added to station 101 (2 + 2 = 4) and so on. ...站100的温度被添加到站101(2 + 2 = 4),等等。
What would be the best way to do this? 最好的方法是什么?
Thanks in advance. 提前致谢。
try something like this: 尝试这样的事情:
select hour,sum(temperature)
from MyTable
group by hour
select hour,sum(temperature) from table_name group by hour;
您需要使用GROUP BY。
SELECT hour, SUM(temperature) FROM myTable GROUP BY hour
Select hour,SUM(temperature) FROM Table GROUP BY hour
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.