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

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



List of Articles
번호 제목 글쓴이 날짜 조회 수
공지 CUBRID 사용자를 위한 DBeaver 도구 출시 안내 admin 2024.04.23 49
공지 SQLGate for CUBRID 영구 무료 라이선스 제공 file admin 2020.04.09 4458
1334 cub_server cpu 사용률 1 bchlim 2021.01.22 275
1333 cub_server cpu 100% 속도저하 1 길찡 2016.12.07 16513
1332 cub_master: 로컬 어드레스를 바인드할 수 없습니다... 중지.... Address already in use 1 모야 2010.06.04 10776
1331 cub_master: Cannot bind local address... aborting.... Permission denied 2 eldrids 2013.05.17 19007
1330 cub_master: Cannot bind local address... aborting.... Address already in use 4 박상현 2008.11.28 83565
1329 cub_manager 연결 관련 문의 3 file 골로가는청춘 2022.09.02 87
1328 cub_manager 관련 질문 4 파인 2021.03.08 191
1327 cub_cmserver 프로세스가 죽어요 3 secret 배운다큐브 2014.06.11 15
1326 cub_admin process 역할 확인 요청 1 nagh 2021.02.15 146
1325 csv 파일 import시 한글 깨짐 관련 1 enak 2015.02.06 16501
1324 csql에서 해당 구문이 작동하지 않네요.. 2 레드오리 2008.12.19 15573
1323 csql를 사용하여 스크립트를 돌리게 되면 에러가 납니다. 1 secret 애정결핍 2013.12.10 6
1322 csql로 연결은 되는데 쿼리가 안되네요 5 하나엘 2009.12.08 13350
1321 csql로 sql파일 실행 시 변수 전달 3 공도비 2022.11.29 136
1320 csql로 .sql가져오기 시, 한글 깨짐 발생 2 도우너19 2022.02.11 391
1319 csql.err 로그에 대해 질문 올립니다. 1 dosem7 2018.01.10 306
1318 csql 환경에서 큐브리드 매니저에 있는 마이그레이션 기능을 사용할수 있을까요? 1 석현진 2017.01.04 14579
1317 csql 출력 결과 string '' 제거 및 구분자 표시 방법 4 nagh 2020.04.23 211
1316 csql 질문드립니다. 1 진영민 2012.05.16 9193
1315 csql 접속 시 에러 2 김진호 2018.07.23 1366
Board Pagination Prev 1 ... 129 130 131 132 133 134 135 136 137 138 ... 200 Next
/ 200

Contact Cubrid

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