안녕하세요
Test1 테이블에 모델명 필드가 있습니다
model = A, B, C, D 는 같이 포함되어도 되지만
model = E, F, G, H 는 같이 포함되면 안되는 경우에
이 쿼리를 어떻게 생성할 수 있나요?
아래 같은 쿼리를 하나의 쿼리문으로 작성이 가능한가요?
고수님들의 답변을 기다립니다
(ex) 1) select * from Test1 where model in ('A','B','C','D')
---> 데이타 존재할 경우
select * from Test1 where model in ('E','F','G','H')
---> 데이타 존재할 경우 에러메세지 리턴
데이타 존재하지 않을 경우 OK 메세지 리턴
2) select * from Test1 where model in ('E','F','G','H')
---> 데이타 존재할 경우
select * from Test1 where model in ('A','B','C','D')
---> 데이타 존재할 경우 에러메세지 리턴
데이타 존재하지 않을 경우 OK 메세지 리턴
Comment 1
-
이스트럭(강동운)
2014.02.04 00:10
안녕하세요.
아래와 같은 쿼리를 활용해볼 수 있겠네요~ 돌려보진 않았습니다 ^^;
감사합니다.
select
case
when first_alphabet > 0 and second_alphabet > 0 then 'ERROR'
when first_alphabet > 0 and second_alphabet = 0 then 'OK'
when second_alphabet > 0 and first_alphabet = 0 then 'OK'
end
from
(
select
sum( case when model in ('A','B','C','D') then 1 else 0 end) as first_alphabet
, sum( case when model in ('E','F','G','H') then 1 else 0 end) as second_alphabet
from test1
) dat