union all에 제한이 있는지 궁금합니다 0 4 2,377

by Tension [MySQL] [2016.04.07 18:48:33]


union all을 반복해서 써야할일이 생겨서 썻는데 

 

어느정도 반복이 넘어가면 Error Code : 1111 Invalid use of group function 이 뜨면서 에러가 납니다..

 

union all에도 횟수 제한이 있는지 궁금합니다

by jkson [2016.04.07 19:31:07]

union all의 문제가 아니라 union all로 붙여준 select 문 중에서 group function을 select 절이 아닌 엉뚱한 곳에 쓴 것 같은데요.. sum이라든지 count라든지.. 하는 group function을 사용한 곳이 어딘지 잘 보세요.

group function은 group by와 같이 쓰여야 하는데 group by 와 같이 쓰지 않은 곳이 있을 것 같네요.

 


by Tension [2016.04.08 09:07:21]

union all 을 하는 과정에 group by절이 있긴하지만 지금 형태가 

A

union all

A

union al l

..

..

..

 

이런형식으로 가는데 20개 까지는 잘 출력이 되다가 

바로 21개째에서 저 오류가 나옵니다

 

잘 출력이 되다가 똑같은 union all을 하나 더붙였다고 나오니 좀 의아하네요 ㅠㅠ


by jkson [2016.04.08 09:19:25]

쿼리문 전체를 올려주시든지 21번째 쿼리를 알려주세요. 해당 쿼리 문제일 듯한데요.

 


by Tension [2016.04.08 10:57:03]
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

 

이런방식으로 돌아갑니다..

댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입