当前位置: 代码迷 >> Sql Server >> 怎么写SQL语句
  详细解决方案

怎么写SQL语句

热度:68   发布时间:2016-04-27 13:57:01.0
如何写SQL语句?


create table tb

(

数字 int,

时间 datetime
)

insert into tb select 10, ' 2011-08-21 02:00:00.000'

insert into tb select 10, ' 2011-08-21 02:10:00.000'

insert into tb select 10, ' 2011-08-21 02:20:00.000'


insert into tb select 20, ' 2011-08-21 03:00:00.000'

insert into tb select 20, ' 2011-08-21 03:10:00.000'

insert into tb select 20, ' 2011-08-21 03:20:00.000'

--我想得到这样格式的报表,该怎样写SQL

日期 时间 数字

2011-08-21 02 30
2011-08-21 03 60

--select sum(数字)from tb where 时间 between '2011-08-21 02:00' and '2011-08-21 02:59'
drop table tb

------解决方案--------------------
SQL code
select max(convert(varchar(10),时间,120)) as 日期,convert(varchar(2),时间,108) 时间,sum(数字) 数字 from tbgroup by convert(varchar(2),时间,108)/*日期         时间   数字---------- ---- -----------2011-08-21 02   302011-08-21 03   60*/
  相关解决方案