+ -
当前位置:首页 → 问答吧 → 求一句多字段SQL

求一句多字段SQL

时间:2011-07-18

来源:互联网

sql 2000数据库
table 表
id
a(数据型int字段)
b(数据型int字段)
c(数据型int字段)
---------------------------
ID a b c
1 40 50 70
2 50 40 90
3 60 80 70
4 20 70 50
5 30 40 50
6 70 80 40
7 40 80 70
-------------------------
一般我们都是使用 这样。SELECT FROM table WHERE a=40 or b=40 or c=40 来查a b c字段是否有40值。
那反应结果:
1 40 50 70
2 50 40 90
5 30 40 50
6 70 80 40
7 40 80 70

现在我想可以不使用“OR”符 也能返回达亲的结果吗。跪求高手
SELECT FROM table WHERE (a+''b+''+c=40) 这样好像不行。

作者: djvvaa   发布时间: 2011-07-18

SQL code
SELECT * FROM table WHERE a+''b+''+c like '%40%'

作者: dogfish   发布时间: 2011-07-18

SQL code
select * from table 
where id in
(
   select id , col from 
   (
      select id , a as col from table 
      union all
      select id , b from table
      union all
      select id , c from table
   ) at t where col = 40
)

作者: aspwebchh   发布时间: 2011-07-18

SQL code
select * from table 
where id in
(
   select id  from 
   (
      select id , a as col from table 
      union all
      select id , b from table
      union all
      select id , c from table
   ) at t where col = 40
)

作者: aspwebchh   发布时间: 2011-07-18

SELECT * FROM table WHERE not(a<>40 and b<>40 and c<>40)

作者: veling   发布时间: 2011-07-18