select car_value=max(case when pid='car' then value else -1 end),
book_value=max(case when pid='book' then value else -1 end),
cup_value=max(case when pid='cup' then value else -1 end),
updatetime from table_info group by updatetime
book_value=max(case when pid='book' then value else -1 end),
cup_value=max(case when pid='cup' then value else -1 end),
updatetime from table_info group by updatetime
解决方案 »
- SQL Server 2008 试用版如何更换序列号?
- 如何打开Sqlserver2005
- 如何设定表的其中两个字段加起来唯一?
- sql数据库报错求解?
- SQLServer中用SQL语句实现以下功能
- 这两句能达到相同效果么?
- 怎样用SQL语句一次将它显示出来?
- 关于db2存储过程的问题!
- 怎样读取Text类型的文本数据,因为text存储的是一个指针把?
- 大家来评价一下ERwin、PowerDesigner、Visio 2002、Rational Rose那个更好?来者有分??
- 两个相同结构表的查询!忘高手指教指教!一个简单的问题!!!
- 小问题,sql 2000中如何用命令建表!!!!!在线等.
car_value=sum(case when pid='car' then value else 0 end),
book_value=sum(case when pid='book' then value else 0 end),
car_value=sum(case when pid='car' then value else 0 end),
book_value=sum(case when pid='book' then value else 0 end),
cup_value=sum(case when pid='cup' then value else 0 end),
updatetime
from table_info
group by updatetime
car_value=sum(car_value),book_value=sum(book_value),cup_value=sum(cup_value),updatetime=max(updatetime)
from
(select
car_value=(case pid when 'car' then value else 0 end),
book_value=(case pid when 'book' then value else 0 end),
cup_value=(case pid when 'cup' then value else 0 end),
updatetime=(case pid when 'updatetime' then updatetime else 0 end)
from table_info) info
group by updatetime
现在出现了新的问题,updatetime 这项的时间是精确到毫秒的
2005-12-19 10:00:00.195
2005-12-19 10:00:00.652
这样的形式,用group by updatetime这样的得出的结果肯定是不行的,因为时间实际是有毫秒级的区别,怎样去掉毫秒的信息,让这两个时间相等?
book_value=max(case when pid='book' then value else -1 end),
cup_value=max(case when pid='cup' then value else -1 end),
updatetime=Convert(varchar(30),updatetime,120)
from table_info
group by Convert(varchar(30),updatetime,120)
0.0 0.0 2005-12-01 01:02:00.000
0.0 0.18 2005-12-01 01:02:30.500
0.74 0.0 2005-12-01 01:02:30.813
0.0 0.0 2005-12-01 01:03:00.000
0.0 0.18 2005-12-01 01:03:30.500
0.74 0.0 2005-12-01 01:03:30.843
0.0 0.0 2005-12-01 01:04:00.000
0.0 0.18 2005-12-01 01:04:30.483
0.74 0.0 2005-12-01 01:04:30.797
0.0 0.0 2005-12-01 01:05:00.000
用的是 churchatp1(别看资料,看聊效!) 的方法
实际上上面的数据中是没有值为0的,现在因为这个毫秒,出来很多个0~~~
book_value=max(case when pid='book' then value else -1 end),
cup_value=max(case when pid='cup' then value else -1 end),
updatetime=Convert(varchar(19),updatetime,120)
from table_info
group by Convert(varchar(19),updatetime,120)