使用多个位列条件选择查询 [英] Select query using multiple where conditions of bit columns

查看:77
本文介绍了使用多个位列条件选择查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello all

我正在进行sql查询,其中我有6位输入。这些输入只有在这些情况下才适用于where子句。仅表示输入将适用于where子句,该子句为true,其余部分将被忽略。如果只有3个输入为真且3个为假,则也应用这些组合。

Plz告诉我我是否必须使用if else来完成所有案例,或者是否有其他/更简单的方法。

解决方案

你的问题不明确但我举了一个例子。你必须尝试,如果帮助你。如果任何一个位字段为真,那么可以显示记录。



 选择 * 来自表1 其中 Field1 = 1  Field2 = 1  Field3 = 1  Field4 = 1  Field5 = 1  Field6 = 1 





如果您只想在所有位字段为真时显示数据,请使用此查询



 中选择 * 表1 其中 Field1 = 1  Field2 = 1  Field3 = 1  Field4 = 1  Field5 = 1  Field6 = 1 


Hello all
I am making a sql query where i have 6 bit inputs.These inputs will be applicable in the where clause only when these are true. Means only that input will be applicable in the where clause which is true and rest of them will be ignored.Here combinations are also applied like if only 3 inputs are true and 3 are false.
Plz tell me whether I have to make all the cases using if else or is there any other/simpler way out.

解决方案

Your question is not clear but I am giving an example. you must try if helps you. If Any one bit field is true so records can be display.

Select * from Table1 where Field1=1 or Field2=1 or Field3=1 or Field4=1 or Field5=1 or Field6=1



If you want to show data only when all bit fields are true so use this query

Select * from Table1 where Field1=1 and Field2=1 and Field3=1 and Field4=1 and Field5=1 and Field6=1


这篇关于使用多个位列条件选择查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆