Background Image

FORUM

2022.08.12 10:22

조건절서브쿼리오류

조회 수 140 추천 수 0 댓글 1
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄


* 질문 등록 시 다음의 내용을 꼭 기입하여 주세요.

OS
 Linux 64bit 등
CUBRID Ver.
11.2
CUBRID TOOL Ver.
sqlgate
응용 환경(API)
 


* CUBRID 응용 오류, SQL 오류 또는 SQL 튜닝 관련된 문의는 반드시 다음의 내용을 추가해 주세요. 비밀글이나 비밀 댓글도 가능합니다.
* 저희가 상황을 이해하고, 재현이 가능해야 알 수 있는 문제들이 많습니다. 가능한 정보/정황들을 부탁합니다.

 

에러 내용 및 재현 방법 재현 가능한 Source와 SQL
관련 테이블(인덱스, 키정보 포함) 정보 CUBRID 홈 디렉토리 아래 log 디렉토리 압축


-------------- 아래에 질문 사항을 기입해 주세요. ------------------------------------------------------------------------

select *
from cg_reg_info t1 left outer join cg_ers_his t2
                                        on t1.lnd_r  = t2.lnd_r
                                       and t1.lnd_no = t2.lnd_no
                                       and t1.app_yr = t2.app_yr
                                       and t1.app_no = t2.app_no
                                       and t1.reg_no = t2.reg_no
                                       and t2.ser_no  =  (select max(ser_no) from cg_ers_his 
                                                     where lnd_r = t1.lnd_r and lnd_no = t1.lnd_no
                                                       and app_yr= t1.app_yr and app_no = t1.app_no
                                                       and reg_no = t1.reg_no 
                                                       and reg_dt = (select max(reg_dt) from cg_ers_his 
                                                                                         where lnd_r = t1.lnd_r and lnd_no = t1.lnd_no
                                                                                       and app_yr= t1.app_yr and app_no = t1.app_no
                                                                                       and reg_no = t1.reg_no)
                                                             )
WHERE t1.app_yr = '2022' AND t1.app_no = '50001'  

 

-----------------------------------------------------------------------------------------------------------------------------------

에러

Cannot use a subquery in join condition clause. 

이 부분 지우면 제대로 실행

and t2.ser_no  =  (select max(ser_no) from cg_ers_his 
                                                     where lnd_r = t1.lnd_r and lnd_no = t1.lnd_no
                                                       and app_yr= t1.app_yr and app_no = t1.app_no
                                                       and reg_no = t1.reg_no 
                                                       and reg_dt = (select max(reg_dt) from cg_ers_his 
                                                                                         where lnd_r = t1.lnd_r and lnd_no = t1.lnd_no
                                                                                       and app_yr= t1.app_yr and app_no = t1.app_no
                                                                                       and reg_no = t1.reg_no)
                                                             )

 

-----------------------------------------------------------------------------------------------------------------------------------

 

where 절에 서브쿼리가 지원이 안되나요????

 

 

select *
from cg_reg_info t1 left outer join cg_ers_his t2
                                        on t1.lnd_r  = t2.lnd_r
                                       and t1.lnd_no = t2.lnd_no
                                       and t1.app_yr = t2.app_yr
                                       and t1.app_no = t2.app_no
                                       and t1.reg_no = t2.reg_no
                                       and t2.ser_no  IN  (1,2
                                                       
                                                             )
WHERE t1.app_yr = '2022' AND t1.app_no = '50001'

 

--> 제대로 실행

 

select *
from cg_reg_info t1 left outer join cg_ers_his t2
                                        on t1.lnd_r  = t2.lnd_r
                                       and t1.lnd_no = t2.lnd_no
                                       and t1.app_yr = t2.app_yr
                                       and t1.app_no = t2.app_no
                                       and t1.reg_no = t2.reg_no
                                       and t2.ser_no  IN  (select ser_no from cg_ers_his  a
                                                     where a.lnd_r = t1.lnd_r and a.lnd_no = t1.lnd_no
                                                       and a.app_yr= t1.app_yr and a.app_no = t1.app_no
                                                       and a.reg_no = t1.reg_no 
                                                       
                                                             )
WHERE t1.app_yr = '2022' AND t1.app_no = '50001'    

 

--> 에러, Cannot use a subquery in join condition clause.                                                                                         

 

 

 

 

 

  • ?
    권호일 2022.08.16 13:36

    안녕하세요.

    CUBRID 11,2에서는 ON절에서 subquery를 아직 지원하지 않고 있습니다.

    문의 주신 쿼리는 분석함수를 사용하여 cg_ers_his 테이블에서 최대 reg_dt와 ser_no에 해당하는 레코드를 1건만 찾아서 cg_reg_info 테이블과 left outer join 하도록 변경하였습니다.

    아래와 같이 변경이 가능하고, 쿼리성능도 더 빨라 질 것으로 예상 됩니다.

    확인 부탁 드리겠습니다.

    감사합니다.



    select *
    from cg_reg_info t1 left outer join
           ( select t2.*
             from ( select t2.*,
                                  ROW_NUMBER() OVER ( PARTITION BY t2.lnd_r, t2.lnd_no, t2.app_yr, t2.app_no, t2.reg_no ORDER BY t2.reg_dt, t2.ser_no DESC ) AS MAX_NUM
                        from cg_ers_his t2
                        where t2.app_yr = '2022' AND t2.app_no = '50001'
                       ) t2
             where t2.MAX_NUM = 1
            ) t2
          on t1.lnd_r = t2.lnd_r
        and t1.lnd_no = t2.lnd_no
        and t1.app_yr = t2.app_yr
        and t1.app_no = t2.app_no
        and t1.reg_no = t2.reg_no
    WHERE t1.app_yr = '2022' AND t1.app_no = '50001'


List of Articles
번호 제목 글쓴이 날짜 조회 수
공지 CUBRID 사용자를 위한 DBeaver 도구 출시 안내 admin 2024.04.23 48
공지 SQLGate for CUBRID 영구 무료 라이선스 제공 file admin 2020.04.09 4458
934 전자정부 프레임워크와 큐브리드 연동하는 방법 알려주세요 1 mytoky 2013.08.29 19202
933 전자정부표준프레임워크 BLOB insert질문합니다 1 poooh 2013.10.24 47436
932 전자정부표준프레임워크 recordset 프로시져 호출 1 없음 2022.01.10 274
931 전체 데이터 용량과 데이터 건수 1 쫑쫑이 2020.09.08 577
930 전체 복구 이후 증분 복구가 오류 납니다. 3 coolkkm 2017.10.20 236
929 전체 자동시작이 되지 않습니다. 2 또랑 2010.12.03 8003
928 전체백업과 아키이브 파일 복원 문의 4 coolkkm 2018.01.26 389
927 전체테이블 1 삐삐 2019.01.28 115
926 접속 자동으로 끊김 6 secret moon 2014.12.24 20
925 접속이 많으면 브로커 에러가 납니다 ㅠㅠ... 1 secret 광황제 2013.11.04 11
924 접속자의 아이피나 맥어드레스를 알아낼수 있는지요 3 유니콘 2012.12.05 10956
923 접속제한 설정 질문드립니다 2 유니콘 2011.12.24 12721
922 정규식 사용법에 대해서 궁금합니다.. 1 큐브리드어려워요 2022.01.11 715
921 정기 교육 관련 문의 드립니다. 1 kings 2012.06.22 6205
920 정기교육 문의 1 마루 2013.01.30 5269
919 정수 변환 2 현수 2019.10.05 805
918 정수/정수 결과를 소수로 출력하게 하는법 1 file suyeon 2022.02.23 197
917 정수와 정수의 나누기.. 1 파란토끼 2013.10.08 10719
916 제로보드 4 이용중인데 최신게시물 불러오기에서 힘드네요 1 secret 헬리 2009.06.03 11
915 제약조건 비활성화 1 삽질중 2009.10.28 9612
Board Pagination Prev 1 ... 149 150 151 152 153 154 155 156 157 158 ... 200 Next
/ 200

Contact Cubrid

대표전화 070-4077-2110 / 기술문의 070-4077-2113 / 영업문의 070-4077-2112 / Email. contact_at_cubrid.com
Contact Sales