创建学生表,内有字段 姓名,年龄,性别,年级 ,(这里我只创建到三年级)
备注 :性别 男/女,,年级 :学前班/一到六年级,,姓名年龄不限
要求: 查询一年级的男生和二到五年级的所有学生
对于以上的查询语句该编写SQL
select * from student where grade in ('一年级','二年级','三年级') and (grade!='一年级' and sex!='女')
select * from student where 1=1 and (grade!='一年级' and grade!='学前班' and sex!='女')
select * from student where grade in ('二年级','三年级') or (grade='一年级' and sex='男')
这里我写出三个SQL,哪一个可以正确执行出结果呢?这里操作一下,返回结果如下:
如图三正是我们想要的结果,第三条SQL是适合我们要求的SQL