database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
ㆍMS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
MS-SQL Q&A 3543 게시물 읽기
No. 3543
좀 도와주십시오..
작성자
왕초보
작성일
2007-06-01 15:21
조회수
3,681

select  ee1.start_day, ee1.ev_ym, ee1.ev_seq  from ev001 ee1  

  inner join ev101 ee2 on ee1.ev_ym = ee2.ev_ym and ee1.ev_seq = ee2.ev_seq

  where  ee1.ev_can_cd is null 

     and ee1.good_type_cd =  'P'  

     and  ee1.area_cd  = 'CH' 

     and  ee1.good_yy =  '2006'  

     and ee1.good_seq  =  96   

     and left(ee1.start_day,4) >= left(getdate(),4)

     and start_day >= convert(varchar(10),getdate(),112) 

order by  ee1.start_day asc, ee2.adult_price asc


결과값

start_day | ev_ym | ev_seq

20070601    070601    84

20070601    070601    568

20070601    070601    55

20070601    070601    59

20070602    070602    73

20070602    070602    37

20070602    070602    42

20070602    070602    36

20070603    070603    27

20070603    070603    28

20070603    070603    60

20070603    070603    436

20070604    070604    60

20070604    070604    361

20070604    070604    27

20070604    070604    32

20070604    070604    26

...........................

...........................

원하는 결과값 

20070601    070601    84

20070602    070602    73

20070603    070603    27

20070604    070604    60


설명 

start_day 순으로 정렬한 후 adult_price 순으로 이차 정렬하고 start_day 중복을 제거한 각각의 start_day 의 맨위의 값을 가져 오고 싶습니다.

어떻게 하면 좋을까요? 원하는 결과값 처럼요~~ 도와주세요~~

이 글에 대한 댓글이 총 2건 있습니다.

출력이 되지 않는 adult_price로 정렬 왜 수행하셨는지 모르겠네요. 제가 보기엔 start_day만 맞게 나오면될 듯 한데요. GROUP BY와 MAX를 이용하시면 될듯합니다.


select  ee1.start_day, ee1.ev_ym, max(ee1.ev_seq)  from ev001 ee1 

  inner join ev101 ee2 on ee1.ev_ym = ee2.ev_ym and ee1.ev_seq = ee2.ev_seq 

  where  ee1.ev_can_cd is null 

     and ee1.good_type_cd =  'P' 

     and  ee1.area_cd  = 'CH' 

     and  ee1.good_yy =  '2006'

     and ee1.good_seq  =  96

     and left(ee1.start_day,4) >= left(getdate(),4)

     and start_day >= convert(varchar(10),getdate(),112)

group by ee1.start_day, ee2.ev_ym

order by  ee1.start_day asc asc

초보님이 2007-06-03 11:22에 작성한 댓글입니다.
이 댓글은 2007-06-03 11:25에 마지막으로 수정되었습니다. Edit

정말감사합니다. 해결되었습니다.

왕초보님이 2007-06-04 09:13에 작성한 댓글입니다. Edit
[Top]
No.
제목
작성자
작성일
조회
3552스토어프로시저에서 like 문이 먹지 않네요^^ [2]
박준식
2007-06-01
3023
3551한 필드내에서의 특수 값 데이타 뽑아내기 [1]
신승범
2007-06-01
2526
3544일괄업데이트 [1]
푸롬이
2007-06-01
2558
3543좀 도와주십시오.. [2]
왕초보
2007-06-01
3681
3542access(mdb)에서 null처리 문제(.net 2.0)? [1]
지화복
2007-06-01
3475
3541Datetime과 SmallDatetime의 차이 ? [2]
김영수
2007-06-01
7286
3540어느것이 성능에 더 좋을까요 ? [2]
김영수
2007-05-31
3043
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.019초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다