안녕하세요 이제 막 쿼리를 배우고 있습니다.
질문을 상세하게 잘 설명해야 할텐데 걱정이네요..
쿼리는 아래와 같습니다.
delete u_i_lp_unit
insert into u_i_lp_unit
select v.*
from
(
select i.*
from (select d.degree_cd,d.business_group_cd,d.area_type_cd,d.gubun,d.sup_type_cd,e.site_area_avg as qty
from (select c.degree_cd,c.business_group_cd,c.area_type_cd,c.gubun,c.sup_type_cd, c.qty
from (select distinct a.degree_cd,a.business_group_cd,a.area_type_cd, b.gubun,
(select b.supply_type_cd
from u_i_supply_type_npms b
where a.sup_type_cd = b.supply_type_cd) as sup_type_cd,0 as qty
from u_i_lp_zone_avg a , (select gubun from u_i_lp_temp ) as b) as c
where ((c.gubun <> '연면적' and c.sup_type_cd like 'F%' or c.sup_type_cd like 'GA')
or (c.gubun = '연면적' and sup_type_cd = 'GA'))) as d , u_i_lp_data e
where d.degree_cd = e.degree_cd
and d.business_group_cd = e.business_group_cd
and d.area_type_cd = e.area_type_cd
and d.sup_type_cd = e.sup_type_cd) as i
where i.gubun in('대지면적')
union all
select c.degree_cd,c.business_group_cd,c.area_type_cd,c.gubun,c.sup_type_cd, c.qty
from (select distinct a.degree_cd,a.business_group_cd,a.area_type_cd, b.gubun,
(select b.supply_type_cd
from u_i_supply_type_npms b
where a.sup_type_cd = b.supply_type_cd) as sup_type_cd,0 as qty
from u_i_lp_zone_avg a , (select gubun from u_i_lp_temp ) as b) as c
where (((c.gubun <> '연면적' and c.sup_type_cd like 'F%' or c.sup_type_cd like 'GA') or (c.gubun = '연면적' and sup_type_cd = 'GA'))
and c.gubun <> '대지면적')
) as v
order by v.business_group_cd,v.area_type_cd,v.gubun
---------------Select 부분만 드레그하여 실행하면 오류는 없습니다 다만, insert into를 할 때 아래와 같은 오류가 발생합니다.-------------
Attempt to insert duplicate key row in object 'u_i_lp_unit' with unique index 'u_i_lp_uni_8663073151'
Msg: 2601, Level: 14, State: 1
Server: sybase_pms, Line: 2
쿼리가 지저분하여 정확한 답변을 꼭 원하지는 않습니다. 스스로 해결할 의지도 있으니 어떠한 도움이라도 고맙게 받겠습니다.
고견 기다리겠습니다. (__) |