Background Image

FORUM

조회 수 11498 추천 수 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. CUBRID 사용자를 위한 DBeaver 도구 출시 안내

    Date2024.04.23 Byadmin Views51
    read more
  2. SQLGate for CUBRID 영구 무료 라이선스 제공

    Date2020.04.09 Byadmin Views4458
    read more
  3. 실 ip db서버 이중화 관련 질문

    Date2024.01.18 Byzexpand Views92
    Read More
  4. 실리콘 맥(M1, ARM) 큐브리드 매니저 지원 문의

    Date2021.12.24 ByDevin Views400
    Read More
  5. 실리콘 맥(M1, ARM) 큐브리드 매니저 지원 문의

    Date2023.01.09 By큐유저 Views238
    Read More
  6. 실시간 Insert처리

    Date2011.10.29 By동해아빠 Views12444
    Read More
  7. 실시간 데이터 합산에 대해서...

    Date2013.08.24 By알칸펠 Views8286
    Read More
  8. 실행 오류 -494 문의

    Date2017.08.20 Byyodongky Views1947
    Read More
  9. 실행 오류 : -1016 문의드립니다.

    Date2019.05.23 By동건 Views348
    Read More
  10. 실행 오류 : -495 Execute: System error 문의드립니다.

    Date2017.08.11 Byyodongky Views559
    Read More
  11. 실행 오류 :-46 (Internal error: slot 3 on page 4231 of volume)

    Date2011.11.09 Byreerror Views26849
    Read More
  12. 실행 중 서비스 갯수에 대해 문의 드립니다.

    Date2013.11.01 By푸추어핸접 Views9201
    Read More
  13. 실행계획 읽는 법 문의 드립니다.

    Date2022.07.01 Bykikiki767 Views260
    Read More
  14. 실행계획이 달라지는 경우에 대해서 문의드립니다.

    Date2019.01.13 By동건 Views573
    Read More
  15. 실행시 오류

    Date2013.04.10 By반갑습니다 Views7
    Read More
  16. 실행이 안됨

    Date2012.11.06 Bykemuel Views7658
    Read More
  17. 실행이 안됩니다

    Date2015.04.21 By사이다 Views6815
    Read More
  18. 실행이 안됩니다.

    Date2017.06.22 By하마 Views1099
    Read More
  19. 아래 918번 글에 대한 답변은 언제쯤...??

    Date2011.02.21 By유니콘 Views7712
    Read More
  20. 아래 문의에 이어 질문드립니다.

    Date2010.07.13 By헬리 Views12
    Read More
  21. 아래 이상 증상 재현 방법 다시 작성합니다.

    Date2020.06.05 By아악이 Views194
    Read More
  22. 아래 질문에 대해서...질의창 실행 안되는 문제

    Date2008.12.19 By초리 Views17473
    Read More
Board Pagination Prev 1 ... 132 133 134 135 136 137 138 139 140 141 ... 200 Next
/ 200

Contact Cubrid

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