select dateadd(mi,(datediff(mi,convert(varchar(10),
dateadd(ss,-1,CreateOn),120),dateadd(ss,-1,CreateOn))/5)*5,convert(varchar(10),CreateOn,120)) as CreateOnss,
count(*) as cnt, MAX(CreateOn),
sum(OrderAmt) as OrderAmtdd
from SaleOrder
where OrderStatus>0 and OrderStatus<=90
and CreateOn>='2014-01-02' and CreateOn<'2014-01-03'
group by dateadd(mi,(datediff(mi,convert(varchar(10),dateadd(ss,-1,CreateOn),120),
dateadd(ss,-1,CreateOn))/5)*5,convert(varchar(10),CreateOn,120))

select dateadd(mi,(datediff(mi,convert(varchar(10),dateadd(ss,1,CreateOn),120),
dateadd(ss,1,CreateOn))/60)*60,convert(varchar(10),CreateOn,120)) as CreateOn,
count(1) as cnt,
sum(OrderAmt) as OrderAmt,sum(OrderAmt)/COUNT(1) as avgAmt
from SaleOrder where OrderStatus>0 and OrderStatus<=90
and CreateOn>='2014-01-02' and CreateOn<'2014-01-03'
group by dateadd(mi,(datediff(mi,convert(varchar(10),dateadd(ss,1,CreateOn),120),dateadd(ss,1,CreateOn))/60)*60,
convert(varchar(10),CreateOn,120))

04-16 07:18