日期:2014-05-18 浏览次数:20561 次
select count(*),convert(varchar(120),a_time,120) from tb group by convert(varchar(120),a_time,120)
------解决方案--------------------
select sum(case when datepart(mi,a_time)=1 then 1 else 0 end) as m1 sum(case when datepart(mi,a_time)=2 then 1 else 0 end) as m2 sum(case when datepart(mi,a_time)=3 then 1 else 0 end) as m3 sum(case when datepart(mi,a_time)=4 then 1 else 0 end) as m4 sum(case when datepart(mi,a_time)=5 then 1 else 0 end) as m5 ............................ sum(case when datepart(mi,a_time)=59 then 1 else 0 end) as m59 sum(case when datepart(mi,a_time)=60 then 1 else 0 end) as m60 from tb
------解决方案--------------------
declare @date datetime select @date = '2012-02-01 12:00:00' select dateadd( mi,-number,@date ) from master.dbo.spt_values a where a.type = 'p' and a.number < 60
------解决方案--------------------
小三 大虾的回答应该是正确的
datediff(hour,time,getdate())=0
这就是取当前1小时内的数据的SQL 语句
------解决方案--------------------
select DATEPART (mi, datetransaction), count(*)
from
(
select datetransaction
from tabletransaction
where datetransaction <= getdate() and datetransaction >= dateadd (mi, -60 , getdate())
) z
group by DATEPART( mi, datetransaction )
------解决方案--------------------
select DATEPART (mi, datetransaction), count(*)
from
(
select datetransaction
from tabletransaction
where datetransaction <= getdate() and datetransaction >= dateadd (mi, -59 , getdate())
) z
group by DATEPART( mi, datetransaction )
-59 才对
------解决方案--------------------
不用写60条啊 用for循环
------解决方案--------------------
不用写60条啊 用for循环
------解决方案--------------------
create table tdate
(
tid int identity(1,1) primary key,
tdate datetime
)
go
insert into tdate
select getdate() union all
select getdate() union all
select getdate() union all
select getdate() union all
select getdate() union all
select getdate() union all
select getdate() union all
select getdate() union all
select getdate() union all
select getdate() union all
select getdate() union all
select getdate()
select count(datepart(mi,ttdate)) as 次数 from tdate where datediff(hh,ttdate,'2012-5-6 8:01:33')=0 group by datepart(mi,ttdate)