结合AND和OR的MySQL查询 [英] MySql query on combination of AND and OR

查看:114
本文介绍了结合AND和OR的MySQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个MySql查询,以便使用AND和OR的组合.我有6个属性,其中我希望一个String出现,而其中一个属性应出现一个强制性线程.

I want to write a MySql query whereby I want to use combination of AND and OR. I have 6 attributes where in I want one String to appear AND there is one attribute in which a compulsory thread should appear.

我的命令如下所示.

Select * from Students where roll_no like '__2011%' and subject1 ='maths' or subject2='maths' or subject3='maths' or subject4='maths' or subject5='maths' or subject6='maths';

我希望数学"至少出现在那些主题属性之一中.除了该Roll之外,查询中还应包含2011. 请帮助我.

I want 'maths' to appear in atleast one of those subject attributes. Along with that Roll no should have 2011 in it as specified in the query. Please help me.

推荐答案

Select * from Students where roll_no like '__2011%' and (subject1 ='maths' or subject2='maths' or subject3='maths' or subject4='maths' or subject5='maths' or subject6='maths');

这篇关于结合AND和OR的MySQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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