结合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');