首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

SQL 交叉表的有关问题

2012-04-04 
求教:SQL 交叉表的问题SQL语句为:select stcd,tm form st_riverwhere stcd61801700 and year(tm)2011 an

求教:SQL 交叉表的问题
SQL语句为:
select stcd,tm form st_river 
where stcd=61801700 and year(tm)=2011 and month(tm)=12 and day(tm)=23
查询的结果如下:
STCDTMZ
618017002011-12-23 00:00:00.000171.760
618017002011-12-23 01:00:00.000171.710
618017002011-12-23 02:00:00.000171.670
618017002011-12-23 03:00:00.000171.630
618017002011-12-23 04:00:00.000171.590
618017002011-12-23 05:00:00.000171.550
618017002011-12-23 06:00:00.000171.520
618017002011-12-23 07:00:00.000171.480
618017002011-12-23 08:00:00.000171.450
618017002011-12-23 09:00:00.000171.420
618017002011-12-23 10:00:00.000171.390
618017002011-12-23 11:00:00.000171.360
618017002011-12-23 12:00:00.000171.340
618017002011-12-23 13:00:00.000171.320
618017002011-12-23 14:00:00.000171.300
618017002011-12-23 15:00:00.000171.290
618017002011-12-23 16:00:00.000171.270
618017002011-12-23 17:00:00.000171.260
618017002011-12-23 18:00:00.000171.260
618017002011-12-23 19:00:00.000171.260
618017002011-12-23 20:00:00.000171.260
618017002011-12-23 21:00:00.000171.270
618017002011-12-23 22:00:00.000171.290
618017002011-12-23 23:00:00.000171.320  

现在我想得到如下的结果:
STCD TM
61801700 0 1 2 23
171.76171.71171.67........... 171.32
0、1、2...23分别代表0时至23时
请问怎么实现,谢谢!

[解决办法]

SQL code
select  STCD,  sum(case when datepart(hh,tm)=1 then z else 0 end) as '1',  sum(case when datepart(hh,tm)=2 then z else 0 end) as '2',.......from  tbgroup by  stcd
[解决办法]
F姐辛苦了

热点排行