比较运算
只显示id,name: select id,name from students;
消除重复行distinct
select distinct gender from students;
条件
select * from students where id>3;
select * from students where isDelete=0;
逻辑运算
- and
- or
- not
select * from students where id>3 and gender=0;
select * from students where id<4 or isDelete=0;
模糊查询
- like
- % : 表示任意多个字符
- _ : 表示一个任意字符
查询姓罗的人:
select * from students where name like '罗%';
查询姓杨 且 名字是一个字的人:
select * from students where name like '杨_';
查询姓薛 且 名字两个字的人:
select * from students where name like '薛__';
查询姓罗 或者 叫嫣 的人:
select * from students where name like '罗%' or name like '%嫣';
范围查询
- in :表示在一个非连续的范围内
- 查询编号是1或3或8的人
select * from students where id in(1,3,8);
- between ... and ... 表示在一个连续的范围内(between后小数,and后大数)
- 查询id是3到8的人
select * from students where id between 3 and 8;
select * from students where id between 3 and 8and gender=1;
空判断
- null与''不相同
- 判断: is null
select * from students where birthday is null;
select * from students where birthday is not null;
优先级
- 小括号, not, 比较运算符, 逻辑运算符
- and比or先运算,如果同时出现并希望先算or,需要结合()使用