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

hum*_*ner 1 sql t-sql sql-server

如何在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)
Run Code Online (Sandbox Code Playgroud)

Joe*_*lli 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))
Run Code Online (Sandbox Code Playgroud)