select * from ( select * from(select 1609 as seq, Min(case time when '09' then rank end) as 'h09', Min(case time when '10' then rank end) as 'h10', Min(case time when '11' then rank end) as 'h11', Min(case time when '12' then rank end) as 'h12', Min(case time when '13' then rank end) as 'h13', Min(case time when '14' then rank end) as 'h14', Min(case time when '15' then rank end) as 'h15', Min(case time when '16' then rank end) as 'h16', Min(case time when '17' then rank end) as 'h17', Min(case time when '18' then rank end) as 'h18', Min(case time when '24' then rank end) as 'h24' from ( select b.rank,a.time from ( SELECT '09' time 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' ) as a left outer join ( select rank,DATE_format(rank_date,'%H') as time from keyword_record where DATE_FORMAT(rank_date,'%Y-%m-%d') like '2016-04-08' and client_collect_seq = 1609 ) as b on a.time = b.time union all select count(rank) as rank ,24 as time from keyword_record where DATE_FORMAT(rank_date,'%Y-%m-%d') like '2016-04-08' and hour(rank_date) >=9 and hour(rank_date) <=18 and client_collect_seq = 1609 ) as b) as c) as z inner join client_collect_info as x where z.seq = x.client_collect_seq
이것이 쿼리문이고 단순하게
select * from
(
<foreach item="item" index="index" collection="list" separator="union all" >
A
</foreach>
) as z
이런방식으로 돌아갑니다..