2012/10/01

SQL CASE WHEN in WHERE

學姊傳授的解法


SLECT A, B, C, STAT FROM TABLE1

WHERE A IN ('091' ,'099')

AND (CASE

WHEN A < '096' AND STAT IN ('1') THEN 'Y'

WHEN A >= '096' AND STAT IN ('2') THEN 'Y'

END) ='Y'

ORDER BY STAT


--


SLECT A, B, C, STAT FROM TABLE1

WHERE A IN ('091' ,'099')

AND(

(A < '096' AND STAT IN ('1','2','3'))

OR

(A >= '096' AND STAT IN ('2','3'))

)

--
※ 發信站: 批踢踢兔(ptt2.cc)
◆ From: 1.200.25.139

沒有留言:

張貼留言