Try this:select shop ,ltrim(str(datepart(hh,yourdatetimefield)))+':00 - '+ltrim(str(datepart(hh,yourdatetimefield)))+':59' as time_span ,sum(case when datediff(dd,yourdatetimefield,getdate())=0 then amt else 0 end ) as current_amount ,sum(case when datediff(dd,yourdatetimefield,getdate())=1 then amt else 0 end ) as yesterday_amount ,sum(amt*case when datediff(dd,yourdatetimefield,getdate())=1 then -1 else 1 end ) as diff_amount ,case sign(sum(amt*case when datediff(dd,yourdatetimefield,getdate())=1 then -1 else 1 end ) ) when 0 then 'Same' when 1 then 'Up' else 'Down' end as amount_direction from yourtable where yourdatetimefield>=cast(dateadd(dd,-1,getdate()) as date) and yourdatetimefield<cast(dateadd(dd,1,getdate()) as date) group by shop ,datepart(hh,yourdatetimefield)