CASE문으로 아주 간단하게 컬럼의 값 비교하기 > db

본문 바로가기
사이트 내 전체검색

db

CASE문으로 아주 간단하게 컬럼의 값 비교하기

페이지 정보

작성자 서방님 댓글 0건 조회 141회 작성일 10-09-08 09:37

본문

혹시 이런 거 쓸일 있을지도 모르겠네요. 무식하게.. 썼습니다.

[여러 컬럼중 가장 큰값 찾아 출력하기]

[예제 테이블과 데이터]
create table testtbl (
 a1 int
, a2 int
, a3 int
, a4 int )

insert into testtbl values (1 , 2 , 3 , 4)
insert into testtbl values (5 , 1 , 2 , 7)
insert into testtbl values (8 , 5 , 3 , 1)

select * from testtbl

[여러 컬럼중 가장 큰값 찾아 출력하기]
select  max( case  when  a1>a2 and a1>a3 and a1>a4 then a1 
when a2 > a3 and a2>a4 then a2
when a3 > a4 then a3 
else a4 
end)  as '여러 컬럼중 가장 큰 값'
from testtbl

댓글목록

등록된 댓글이 없습니다.

회원로그인

접속자집계

오늘
132
어제
225
최대
1,347
전체
154,891
Latest Crypto Fear & Greed Index

그누보드5
Copyright © 서방님.kr All rights reserved.