하은양 믿음군 효실맘 호홍홍집s

Mysql union all이용한 시간단위 값가져오기 편법 ㅋㅋ 본문

가벼운 배움/MySql

Mysql union all이용한 시간단위 값가져오기 편법 ㅋㅋ

호홍홍집 2016. 2. 26. 17:10
select a.*,
  (select ifnull(count(rsv_id),0) cnt from TB_RSV 
    where OBJ_TYPE = 'GRP' and OBJ_ID = 1 and RSTATUS in ('POK') 
    and DATE_FORMAT(stime, '%Y%m%d%H') = concat('20160225',a.team_h)
  ) rsvcnt
from 
(
  select 1 AS num, '09:00' AS team_hour, '09' AS team_h
  union all
  select 2 AS num, '10:00' AS team_hour, '10' AS team_h
  union all
  select 3 AS num, '11:00' AS team_hour, '11' AS team_h
  union all
  select 4 AS num, '12:00' AS team_hour, '12' AS team_h
  union all
  select 5 AS num, '13:00' AS team_hour, '13' AS team_h
  union all
  select 6 AS num, '14:00' AS team_hour, '14' AS team_h
  union all
  select 7 AS num, '15:00' AS team_hour, '15' AS team_h
  union all
  select 8 AS num, '16:00' AS team_hour, '16' AS team_h
  union all
  select 9 AS num, '17:00' AS team_hour, '17' AS team_h
) a
;