select LPAD(0,2,0) as sj
union all select LPAD(1,2,0)
union all select LPAD(2,2,0)
union all select LPAD(3,2,0)
union all select LPAD(4,2,0)
union all select LPAD(5,2,0)
union all select LPAD(6,2,0)
union all select LPAD(7,2,0)
union all select LPAD(8,2,0)
union all select LPAD(9,2,0)
union all select 10
union all select 11
union all select 12
union all select 13
union all select 14
union all select 15
union all select 16
union all select 17
union all select 18
union all select 19
union all select 20
union all select 21
union all select 22
union all select 23
from dual
如图:
select LPAD(0,2,0) as sj
union all select LPAD(1,2,0)
union all select LPAD(2,2,0)
union all select LPAD(3,2,0)
union all select LPAD(4,2,0)
union all select LPAD(5,2,0)
union all select LPAD(6,2,0)
union all select LPAD(7,2,0)
union all select LPAD(8,2,0)
union all select LPAD(9,2,0)
union all select 10
union all select 11
union all select 12
union all select 13
union all select 14
union all select 15
union all select 16
union all select 17
union all select 18
union all select 19
union all select 20
union all select 21
union all select 22
union all select 23
from dual
<!-- 按小时计算 -->
<select id="getValGroupHour" resultType="map" parameterType="java.util.Map">
select ta.sj sj, ifnull(tb.avg,0) avg from (<include refid="day"></include>) ta
left join (
SELECT
DATE_FORMAT(bjsj,'%H') sj, COUNT(*)/#{interval,jdbcType=INTEGER} avg
FROM b_jtsg_jjd jjd
where bjsj > #{kssj,jdbcType=TIMESTAMP}
and #{jssj,jdbcType=TIMESTAMP} > bjsj
group by DATE_FORMAT(bjsj,'%H')
) tb on ta.sj = tb.sj
</select>