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 4149 게시물 읽기
No. 4149
쿼리 질문 드립니다...
작성자
남용욱
작성일
2008-03-31 11:06
조회수
3,755


   쿼리 질문 드립니다. 



   순서  |   종류    |   X 값    |  Y 값   |


    1         a_type      300          0

    2         b_type      20          2

    3         b_type      330          3

    4         b_type      310          0

    5         a_type      310          0

    6         b_type      3100          0

    7         b_type      3100          0

    8         b_type      330          0

    9         c_type      3300          0

   10         c_type      410          0

   11         c_type      300          0

   12         c_type      340          0

   13         c_type      20          0

   14         c_type      10          0

   15         c_type      3100          0

   16         c_type      100          0

   17         c_type      100          0




  테이블이 있는데 


    종류        순서      x    y

   a_type      5          310   0

   b_type      8          330   0

   c_type     17          100   0


   순서가 젤 높은것부터 종류를 묵어서 해당 값을 보고 싶습니다. 셀프 조인해서 할려구해도 max 값을가지고 비교가 안되니....

  

   

  


  

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

create table #testTB
(r_num int
, kind varchar(10)
, x int
, y int)
go


insert into #testTB
select  * from
(
select r_num =  1,  kind = 'a_type', x =  300 , y =  0    union all
select r_num =  2,  kind = 'b_type', x =  20  , y = 2     union all
select r_num =  3,  kind = 'b_type', x =  330 , y =  3    union all
select r_num =  4,  kind = 'b_type', x =  310 , y =  0    union all
select r_num =  5,  kind = 'a_type', x =  310 , y =  0    union all
select r_num =  6,  kind = 'b_type', x =  3100, y =   0   union all
select r_num =  7,  kind = 'b_type', x =  3100, y =   0   union all
select r_num =  8,  kind = 'b_type', x =  330 , y =  0    union all
select r_num =  9,  kind = 'c_type', x =  3300, y =   0   union all
select r_num = 10,  kind = 'c_type', x =  410 , y =  0    union all
select r_num = 11,  kind = 'c_type', x =  300 , y =  0    union all
select r_num = 12,  kind = 'c_type', x =  340 , y =  0    union all
select r_num = 13,  kind = 'c_type', x =  20  , y = 0     union all
select r_num = 14,  kind = 'c_type', x =  10  , y = 0     union all
select r_num = 15,  kind = 'c_type', x =  3100, y =   0   union all
select r_num = 16,  kind = 'c_type', x =  100 , y =  0    union all
select r_num = 17,  kind = 'c_type', x =  100 , y =  0
) q
go


select a.* from #testTB a
inner join (
 select kind, r_num = max(r_num)  from #testTB
 group by kind
) b
on a.r_num = b.r_num
and a.kind = b.kind
order by kind

 
.님이 2008-03-31 11:15에 작성한 댓글입니다. Edit

감사 합니다!!!


남용욱님이 2008-03-31 15:46에 작성한 댓글입니다. Edit
[Top]
No.
제목
작성자
작성일
조회
4152SQL과 C++과 포토샾을이용해서 프로그램을만들려고하는데요~
장활
2008-04-01
3887
4151group by 와 order by 쓸때의 차이점관해서 질문입니다. [3]
최인배
2008-03-31
4752
4150페이징 처리를 위한 인라인뷰 사용시 질문 [1]
김무량
2008-03-31
7769
4149쿼리 질문 드립니다... [2]
남용욱
2008-03-31
3755
4148네트워크 접속에 관해서 문의드립니다.
정명규
2008-03-31
4044
4147[질문]Windows Small Business Server 2003 R2 설치/운영해신분 ??? [1]
정규성
2008-03-29
4134
4146정말 급한데요.분사트랜잭션 오류 때문에..
황재훈
2008-03-28
4336
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.019초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다