MySql查询结果过滤同时知足多个条件的数据

建立学生表,内有字段 姓名,年龄,性别,年级  ,(这里我只建立到三年级)3d

备注 :性别 男/女,,年级 :学前班/一到六年级,,姓名年龄不限
要求: 查询一年级的男生和二到五年级的全部学生blog

对于以上的查询语句该编写SQLselect

select * from student where grade in ('一年级','二年级','三年级') and (grade!='一年级' and sex!='女')im

select * from student where 1=1 and  (grade!='一年级' and grade!='学前班'  and sex!='女')查询

select * from student where grade in ('二年级','三年级') or (grade='一年级' and sex='男')db

这里我写出三个SQL,哪个能够正确执行出结果呢?这里操做一下,返回结果以下:img

 

如图三正是咱们想要的结果,第三条SQL是适合咱们要求的SQLdba

相关文章
相关标签/搜索