日期:2014-05-18  浏览次数:20657 次

求助:如何写一条SQL语句(SQLSERVER2000 或 Oracle)
如下3天的记录(片段),要求将这3天的小时相同的记录做累计(每天每个小时有一条记录),最终为1条记录
var_id var_value create_time  
-------------------------------------------------
850 144.725 2011-08-18 14:59:59.000
850 184.167 2011-08-18 15:59:59.000
850 236.176 2011-08-18 16:59:59.000
... ... ...
850 200.568 2011-08-19 14:59:59.000
850 197.352 2011-08-19 15:59:59.000
850 211.072 2011-08-19 16:59:59.000  
... ... ...
850 198.017 2011-08-20 14:59:59.000
850 183.741 2011-08-20 15:59:59.000
850 220.509 2011-08-20 16:59:59.000  

合并后结果为(以小时为字段):
var_id H0 ... H14 H15 H16 ... H23  
-------------------------------------
850 ... ... 543.31 565.26 667.757 ... ...

要求:由于是C++应用,只用一条SQL语句,游标之类不行。谢谢~

------解决方案--------------------
case when
------解决方案--------------------
http://topic.csdn.net/u/20080614/17/22e73f33-f071-46dc-b9bf-321204b1656f.html