sql其中ActionID在Case x = 0,然后id在(1,2,3,4)当x = 1然后id in(1,2)当x = 2 id in(3,4)

时间:2011-10-20 15:32:47

标签: sql sql-server tsql

如何在sql where子句中表示以下条件?

where id in 
  Case x=0 then (1,2,3,4) 
  case x=1 then (1,2) 
  case x=2 then (3,4)

1 个答案:

答案 0 :(得分:10)

...
 WHERE (x=0 AND id IN (1,2,3,4))
    OR (x=1 AND id IN (1,2))
    OR (x=2 AND id IN (3,4))