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 31
공지 SQLGate for CUBRID 영구 무료 라이선스 제공 file admin 2020.04.09 4457
3853 8.4.4버젼 charset 확인 3 네오랜덤 2023.05.23 190
3852 쿼리 속도 차이 질문 1 하얀미스 2023.05.18 143
3851 spring boot 에서 HikariPool-1 - Driver does not support get/set network timeout for connections. (java.lang.UnsupportedOperationException) 질문 드립니다. 3 kjaminam 2023.05.18 781
3850 cci 프로그래밍에서 DB LINK 관련 문의 4 jjune1206 2023.05.18 131
3849 큐브리드 매니저 실행이 오류 1 file 청주시청 2023.05.18 101
3848 ddl 추출 1 네오랜덤 2023.05.17 104
3847 하나의 쿼리에서 복수 테이블 업데이트 방법 문의 4 도담도담 2023.05.17 134
3846 cubrid driver 설치 문의 1 고구망구망 2023.05.08 437
3845 큐브리드 매니저 접속 이 안됩니다. 확인 요청 드립니다. 1 뿡이 2023.04.28 128
3844 Fk값 가져오기 2 file 네오랜덤 2023.04.24 165
3843 서버 메모리 교체 및 ha 상 데이터 삭제 절차 1 레피엘 2023.04.20 112
3842 java stored procedure 에 loadjava 로 jar 파일 로드 시 java.lang.ClassNotFoundException 에러 문의 3 개미가불쌍해 2023.04.18 147
3841 Cubrid stored procedure 스케쥴 등록 형식 2 Roy 2023.04.17 112
3840 암호화 함수 MDB_ENC 질문입니다 1 BE-DEV 2023.04.17 82
3839 auto_increment 추가 방법 문의 1 부패방지운영팀 2023.04.14 265
3838 CUBRID 사용자 계정 생성 관련 문의 1 몽키스패너 2023.04.14 130
3837 order by 이후 rownum이 의도와 다르게 찍힙니다. 2 바보똥개 2023.04.14 143
3836 백업 및 복구 시 cubrid 버전 간 호환 문의 1 플레이어블 2023.04.13 71
3835 centos8에서 쉘스크립트 실행시 csql: command not found 오류 발생 6 kjn4345 2023.04.13 179
3834 큐브리드 timestamp 오류 문의 5 jjun7204 2023.04.12 152
Board Pagination Prev 1 ... 3 4 5 6 7 8 9 10 11 12 ... 200 Next
/ 200

Contact Cubrid

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