select a.hh,sum(isnull(dtrn,0)) as dtrn
from (select 1 as hh union all
      select 2 as hh union all
      ...
      select 24 as hh union all) a,表 b
where a.hh=hour(b.YMDHM)
group by a.hh