1

我想创建一个这样的 sql 查询:

Select* from Table where 
(if picod=1)
{
  dvdt= "xxxx" 
}
(if picod=2)
{
  cddt= "xxxx" 
}
(if picod=3)
{
  bldt= "xxxx" 
}
(if picod=3)
{
  fadt= "xxxx" 
}

我不知道如何在 SQL 中执行此操作。

任何人都可以帮助我吗?

非常感谢 :)

4

3 回答 3

4
Select* from Table 
where (picod=1 and dvdt= 'xxxx') or  (picod=2 and cddt= 'xxxx') or ....... (XXXX) or....
于 2013-02-01T10:19:06.137 回答
3

只需使用OR

SELECT  *
FROM    Table
WHERE   (Picod = 1 AND dvdt = 'xxxx')
OR      (Picod = 2 AND cddt = 'xxxx')
OR      (Picod = 3 AND bldt = 'xxxx')
OR      (Picod = 3 AND fadt = 'xxxx');
于 2013-02-01T10:19:55.443 回答
0
 SELECT  *
    FROM    Table
    WHERE  'xxxx' = case Picod  
     when 1 then dvdt
     when 2 then cddt
     when 3 then bldt 
     when 4 then fadt 
    end
于 2013-02-02T06:21:30.773 回答