Background Image

FORUM

조회 수 11497 추천 수 0 댓글 3
?

단축키

Prev이전 문서

Next다음 문서

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

학생정보와, 시험정보가 있습니다.

그리고 각 학생들이

가장 잘한 시험의 날짜 및 점수,
가장 못한 시험의 날짜 및 점수

이렇게 뽑으려고 합니다.

create class people(
    name varchar(20),
    age short
);

create class exam(
    whois people,
    whenis date,
    point float
);

insert into people values('김', 12) into p1;
insert into people values('이', 13) into p2;
insert into people values('박', 14) into p3;
insert into people values('홍', 15) into p4;

insert into exam values(p1, date'1/2/2009', 60);
insert into exam values(p1, date'1/4/2009', 70);
insert into exam values(p1, date'1/6/2009', 75);
insert into exam values(p2, date'1/7/2009', 80);
insert into exam values(p2, date'1/8/2009', 76);
insert into exam values(p3, date'1/9/2009', 99);

select name, age, exam_good.whenis, exam_good.point, exam_bad.whenis, exam_bad.point from (
select name, age,
(select exam from exam where whois = people order by point desc for orderby_num() = 1) exam_good,
(select exam from exam where whois = people order by point for orderby_num() = 1) exam_bad
 from people
 ) A;

제가 원하는 결과는 다음과 같습니다.

김   12   1/6/2009   75   1/2/2009   60
이   13   1/7/2009   80   1/8/2009   76
박   14   1/9/2009   99   1/9/2009   99
홍   15     NULL    NULL    NULL    NULL

하지만 해보면 다음과 같이 나옵니다.

김   12   1/6/2009   75     NULL    NULL
이   13   1/7/2009   80     NULL    NULL
박   14   1/9/2009   99     NULL    NULL
홍   15     NULL    NULL    NULL    NULL

전 제가 뭔가 잘못한 줄 알았는데, 아무래도 이건 버그 같습니다.

select name, (select exam from exam where whois = people order by point desc for orderby_num() = 1)  from people;
이건 됩니다.

select (select exam from exam where whois = people order by point desc for orderby_num() = 1), name  from people;
이건 안됩니다.

순서를 바꿨다고안되는건 무슨상황인가요

  • ?
    말씀하신 내용에 대해서 추가적으로 살펴보고 있습니다. 
    확인 내용이 나오면 추가적인 답변을 드리도록 하겠습니다.
    현재 원하시는 결과를 도출하기 위해서는  Primary key, foreign key를 이용하여 테이블을 생성하여 쿼리를 만드시기를 권장합니다. PK. FK를 이용하여 생성한 후 원하는 결과를 위한 쿼리 예제를 첨부합니다. 
  • ?
    admin 2009.03.10 18:25
    해당문제는 CUBRID2008 최신버젼에서 패치되어있읍니다.
    특별한 문제가 없으시다면 최신버젼으로의 업그레이드를 권장합니다. 아울로 7.3관련 질문은 홈페이지 첫화면 우측하단의 7.3이하 게시판 이용을 부탁드립니다.
  • ?
    서경식 2009.03.11 00:33
    subquery가 (select a from ... order by b) 와 같이 order by에 hidden column(select 절에 나타나지 않는 칼럼)이 있으면,
    내부적으로 (select a, b from ... order by 2) 로 바꾸어서 수행하게 됩니다.
    문제는 이런 패턴의 subquery가 from 절이 아니고 select 절에 나타나는 경우입니다.
    select 절에 쓸 수 있는 subquery는 1-column만 가져야 하는데, 2 개 이상의 칼럼을 가지는 subquery가 되기 때문에 내부적으로 결과가 틀려지게 됩니다. 
    우회안은, 문제의 subquery 를 derived로 한 번 싸면 됩니다. 

    csql> ;list

       1  select    name, age,
       2    exam_good.whenis, exam_good.point,
       3    exam_bad.whenis, exam_bad.point
       4  from (
       5    select name, age,
       6            ( select exam
       7              from (
       8                    select exam, point
       9                    from exam
      10                    where whois = people
      11                    order by 2 desc for orderby_num() = 1
      12                         ) good(exam, point)
      13            ) exam_good,
      14            (
      15                    select exam
      16                    from (
      17                    select exam, point
      18                    from exam
      19                    where whois = people
      20                    order by 2 for orderby_num() = 1
      21                   ) bad(exam, point)
      22            ) exam_bad
      23    from people
      24   ) A;

      name                     age  exam_good.whenis  exam_good.point  exam_bad.whenis  exam_bad.point
    ==================================================================================================
      '김'                      12  01/06/2009           7.500000e+01  01/02/2009         6.000000e+01
      '이'                      13  01/07/2009           8.000000e+01  01/08/2009         7.600000e+01
      '박'                      14  01/09/2009           9.900000e+01  01/09/2009         9.900000e+01
      '홍'                      15  NULL                         NULL  NULL                       NULL

    이 버그는 예전부터 확인한 사항입니다만, 우회안이 있는 상황이고, 그 발생 빈도에 비해 해결 비용이 크다고 생각되어 해결의 우선 순위가 높지 않다고 분류된 이슈입니다.



  1. SQLGate for CUBRID 영구 무료 라이선스 제공

    Date2020.04.09 Byadmin Views4443
    read more
  2. PHP + Apache + Cubrid 연동 질문 입니다.

    Date2011.07.27 By지누 Views11347
    Read More
  3. Oracle 사용자 팁 문의

    Date2011.07.26 By비형여자 Views9689
    Read More
  4. exception 문의

    Date2011.07.22 By비형여자 Views7839
    Read More
  5. CUBRID DB 호스팅 시 UTF-8 타입 사용.

    Date2011.07.19 Byezzone Views7656
    Read More
  6. 데이타베이스 또는 테이블스페이스 생성 시 자동증가 옵션이 어떻게 되는지??

    Date2011.07.19 By풀소리 Views9849
    Read More
  7. HA 복제시 매니저에서의 테이블 생성

    Date2011.07.15 By유니콘 Views18502
    Read More
  8. [급]Cubrid메니저에서 Unlod 후 load시 오류

    Date2011.07.15 By별솔아범 Views23906
    Read More
  9. HA관련 CUBRID Manager 에서 대시보드 문의드립니다...

    Date2011.07.13 By반짝이 Views25736
    Read More
  10. JSP에서 데이터베이스 연결 어떻게 해요?

    Date2011.07.12 ByJH Views12167
    Read More
  11. migration tool을 이용해 마이그레이션 작업 중 테이블의 데이터 적재 실패 문제

    Date2011.07.11 By엔하늘 Views10171
    Read More
  12. PDO가 지원되고 있는 건가요?

    Date2011.07.09 Bykkh Views10663
    Read More
  13. garbage_collection=yes 설정시 CM(테이블편집-SQL문 탭) 문제입니다...

    Date2011.07.09 By반짝이 Views8646
    Read More
  14. 3.1에서 4.0 업그레이드 후

    Date2011.07.08 By유겸아빠 Views8037
    Read More
  15. 4.0 HA ha_db_list 설정 관련 질문드립니다.

    Date2011.07.08 By반짝이 Views24401
    Read More
  16. php driver interface...x64

    Date2011.07.08 Byplatanus Views7661
    Read More
  17. 참조를 이용해서 찾을때 인덱스를 태울려면 어떻게 하나요?

    Date2011.07.08 By안지민 Views7538
    Read More
  18. 큐브리드 서비스 시작시 오류메시지 해결 방법

    Date2011.07.05 By종이 Views13596
    Read More
  19. Sulinux 64Bit 와 CUBRID 4.0 정식 버젼 체크좀 부탁드립니다...

    Date2011.07.05 By반짝이 Views8446
    Read More
  20. CUBRID 4.0 64bit & SULinux 2.0 64Bit service start 시 manager fail 발생합니다..

    Date2011.07.02 By반짝이 Views10058
    Read More
  21. cci_connect 의 에러코드에 관하여 질문드립니다

    Date2011.06.29 By엥꼬 Views9886
    Read More
Board Pagination Prev 1 ... 143 144 145 146 147 148 149 150 151 152 ... 200 Next
/ 200

Contact Cubrid

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