수불관련 Query를 사용하여 조회를 하고 있습니다..그런데 이 Query를 돌릴때 마다 로드가 많이 걸리는것 같아..

View를 사용하고자 하는데...어찌 해야 하는지 잘몰라 질문 드립니다...


사용툴을 델파이 입니다...


select distinct
         A.met_id, B.met_name,
       
         ((select CASE WHEN sum(in_qty) IS NULL THEN 0 ELSE sum(in_qty) END
          from tbl_sumhouse as A1
          where A1.met_id = A.met_id
             and A1.kind_id ='99'
             and A1.inout_day >=:jday1
             and A1.inout_day <:jday1 ) +

          (select CASE WHEN sum(in_qty) IS NULL THEN 0 ELSE sum(in_qty) END
          from tbl_sumhouse as A10
          where A10.met_id = A.met_id
             and A10.kind_id = '00'
             and A10.inout_day >=:sday10
             and A10.inout_day <:eday10 ) -
 
          (select CASE WHEN sum(in_qty) IS NULL THEN 0 ELSE sum(in_qty) END
          from tbl_sumhouse as A11
          where A11.met_id = A.met_id
             and A11.kind_id = '01'
             and A11.inout_day >=:sday11
             and A11.inout_day <:eday11)) -

        ((select CASE WHEN sum(out_qty) IS NULL THEN 0 ELSE sum(out_qty) END
          from tbl_sumhouse as A12
          where A12.met_id = A.met_id
             and A12.kind_id = '00'
             and A12.inout_day >=:sday12
             and A12.inout_day <:eday12) -
  
          (select CASE WHEN sum(out_qty) IS NULL THEN 0 ELSE sum(out_qty) END
          from tbl_sumhouse as A13
          where A13.met_id = A.met_id
             and A13.kind_id = '02'
             and A13.inout_day >=:sday13
             and A13.inout_day <:eday13) ) AS junjan ,


          (select CASE WHEN sum(in_qty) IS NULL THEN 0 ELSE sum(in_qty) END
          from tbl_sumhouse as A2
          where A2.met_id = A.met_id
             and A2.kind_id = '00'
             and A2.inout_day >=:sday2
             and A2.inout_day <=:eday2) AS jipgo ,
    
        
          (select CASE WHEN sum(in_qty) IS NULL THEN 0 ELSE sum(in_qty) END
          from tbl_sumhouse as A3
          where A3.met_id = A.met_id
             and A3.kind_id = '01'
             and A3.inout_day >=:sday3
             and A3.inout_day <=:eday3) AS jipgoban ,
     
          ((select CASE WHEN sum(in_qty) IS NULL THEN 0 ELSE sum(in_qty) END
          from tbl_sumhouse as A4
          where A4.met_id = A.met_id
             and A4.kind_id = '00'
             and A4.inout_day >=:sday4
             and A4.inout_day <=:eday4) -
  
          (select CASE WHEN sum(in_qty) IS NULL THEN 0 ELSE sum(in_qty) END
          from tbl_sumhouse as A5
          where A5.met_id = A.met_id
             and A5.kind_id = '01'
             and A5.inout_day >=:sday5
             and A5.inout_day <=:eday5)) AS netipgo ,

         (select CASE WHEN sum(out_qty) IS NULL THEN 0 ELSE sum(out_qty) END
          from tbl_sumhouse as A6
          where A6.met_id = A.met_id
             and A6.kind_id = '00'
             and A6.inout_day >=:sday6
             and A6.inout_day <=:eday6) AS jout ,

         (select CASE WHEN sum(out_qty) IS NULL THEN 0 ELSE sum(out_qty) END
          from tbl_sumhouse as A7
          where A7.met_id = A.met_id
             and A7.kind_id = '02'
             and A7.inout_day >=:sday7
             and A7.inout_day <=:eday7) AS joutban ,

          ((select CASE WHEN sum(out_qty) IS NULL THEN 0 ELSE sum(out_qty) END
          from tbl_sumhouse as A8
          where A8.met_id = A.met_id
             and A8.kind_id = '00'
             and A8.inout_day >=:sday8
             and A8.inout_day <=:eday8) -
  
          (select CASE WHEN sum(out_qty) IS NULL THEN 0 ELSE sum(out_qty) END
          from tbl_sumhouse as A9
          where A9.met_id = A.met_id
             and A9.kind_id = '02'
             and A9.inout_day >=:sday9
             and A9.inout_day <=:eday9)) AS netout ,

            ((select CASE WHEN sum(in_qty) IS NULL THEN 0 ELSE sum(in_qty) END
          from tbl_sumhouse as A14
          where A14.met_id = A.met_id
             and A14.kind_id = '99'
             and A14.inout_day >=:jday14
             and A14.inout_day <:jday14 ) +

          (select CASE WHEN sum(in_qty) IS NULL THEN 0 ELSE sum(in_qty) END
          from tbl_sumhouse as A15
          where A15.met_id = A.met_id
             and A15.kind_id = '00'
             and A15.inout_day >=:sday15
             and A15.inout_day <=:eday15 ) -
 
          (select CASE WHEN sum(in_qty) IS NULL THEN 0 ELSE sum(in_qty) END
          from tbl_sumhouse as A16
          where A16.met_id = A.met_id
             and A16.kind_id = '01'
             and A16.inout_day >=:sday16
             and A16.inout_day <=:eday16)) -

         ((select CASE WHEN sum(out_qty) IS NULL THEN 0 ELSE sum(out_qty) END
          from tbl_sumhouse as A17
          where A17.met_id = A.met_id
             and A17.kind_id = '00'
             and A17.inout_day >=:sday17
             and A17.inout_day <=:eday17) -
  
          (select CASE WHEN sum(out_qty) IS NULL THEN 0 ELSE sum(out_qty) END
          from tbl_sumhouse as A18
          where A18.met_id = A.met_id
             and A18.kind_id = '02'
             and A18.inout_day >=:sday18
             and A18.inout_day <=:eday18 )) AS dangjan


from tbl_sumhouse A, tbl_metrial B
where A.met_id = B.met_id

group by A.met_id, B.met_name
order by A.met_id asc

No. Subject Author Date Views
Notice 2023년 1월 - SQLER의 업데이트 강좌 리스트 코난(김대우) 2023.01.02 451
8870 커서 사용안하고 SP insert 방법 문의드립니다. [2] 사이비 2015.07.30 2954
8869 문자열 합치기 어떻게 해야 할까요? [1] 박형준_290570 2015.07.30 4034
8868 GROUP BY 질문입니다. 월마다 범위가 다르게 그룹을 할수 있을까요? [3] 잉구리앵 2015.07.30 3073
8867 프로시저 재컴파일 관련 문의 드립니다. 나는짱이야 2015.07.30 2679
8866 insert ~ select 질문 [1] 쵸보 2015.07.29 2800
8865 마스터 디테일 테이블 마이그레이션 BroadWay 2015.07.29 3225
8864 급..ㅠ sort 방법좀 알려주세요 [6] adam0126 2015.07.29 2885
8863 전일자 재고 수량 계산 Query [1] 슈토파이터 2015.07.29 4691
8862 varbinay 필드의 인덱스 성능 [5] 버즈베잇 2015.07.29 2684
8861 데이터 삭제시 소요시간 예측할 수 있나요. [1] 흑흑 2015.07.29 4232
8860 필드속성 COLLATE Korean_Wansung_CI_AI 바꾸기.. [2] pobiblue 2015.07.28 4945
8859 기간(일) 계산 후 임시테이블에 삽입 [2] 변닷컴 2015.07.28 3349
8858 날짜로 몇일이 지났는지 계산 가능할까요? [3] 변닷컴 2015.07.28 4645
8857 안녕하세요. 최신 패치 정보는 어디서 확인하는지 궁금합니다. [2] SQLerBeginner 2015.07.27 3552
8856 대량 데이터 유입시 실행계획 관련 질문드립니다. [3] 나는짱이야 2015.07.27 3239
8855 sql exprssion 연결문자열 [1] 민성 2015.07.27 2701
8854 MS-Word 형식 문자열은 DB 저장시 어떻게 변환되는 건가요??? [1] 잉구리앵 2015.07.27 2680
8853 SELECT 쿼리 질문드려요.부탁드립니다. [3] ngbrother 2015.07.24 3249
» 중첩 Query를 view 로 사용하고 하는데..어찌 하는지요? [1] 슈토파이터 2015.07.23 3356
8851 웹(jsp)에서 원격으로 mssql서버(윈도우인증모드)에 접속하려면... [1] 깔샴이 2015.07.23 4906





XE Login