我有一张类似
的表格ServicePointID EndTime Energy Usage
1 2004-01-01 06:30:00.00 6075Kwh
2 2004-01-01 06:30:00.00 14000Kwh
3 2004-01-01 06:30:00.00 1250Kwh
4 2004-01-01 06:30:00.00 40Kwh
1 2004-01-01 07:00:00.00 7106Kwh
2 2004-01-01 07:00:00.00 10000Kwh
3 2004-01-01 07:00:00.00 11000Kwh
4 2004-01-01 07:00:00.00 12000Kwh
...
我试图将给定时间戳的所有值相加, 有点像
EndTime Energy Usage Total
2004-01-01 06:30:00.00 21365Kwh
2004-01-01 07:00:00.00 40106Kwh
答案 0 :(得分:1)
我建议不要存储Kwh,但如果你真的需要,这里有一个查询来帮助你理解这个想法。请注意,这是在SQL Server中,我不确定这是否是最好的方法。希望这有帮助
SELECT [EndTime] ,
CAST(SUM(CAST(LEFT([Energy Usage], LEN([Energy Usage]) - 3) AS
NUMERIC)) AS VARCHAR(max)) + 'Kwh'
FROM @table
GROUP BY [EndTime];
答案 1 :(得分:-1)
select endtime, sum(energyusage) as Energy_Usage_Total
from table_name
group by endtime;