9.2基础查询
9.2.1查询所有的列
*表示所有列
##查询所有的员工信息
Select * from emp;
9.2.2查询指定列
输入特指表里的单独列名进行查询
Select empno,ename,depton from emp;
9.3条件查询where
9.3.1常见的运算符
关系运算符:=、!=、<>、>=、<=
区间:between A and B -》[A,B]
And:并且,和
Or:或者
Not:否,非
Is Not null:非空
In:在什么里面
9.3.2查询年龄为65的女学生(where,and)
Select * from stu where age="65" and gender="female";
+--------+-------+------+--------+
| sid | sname | age | gender |
+--------+-------+------+--------+
| S_1004 | liSi | 65 | female |
+--------+-------+------+--------+
9.3.3查询学号为S_1001或名字为lisi的记录(where,or)
Select * from stu where sid="S_1001"or sname="lisi";
+--------+-------+------+--------+
| sid | sname | age | gender |
+--------+-------+------+--------+
| S_1001 | liuYi | 35 | male |
| S_1004 | liSi | 65 | female |
+--------+-------+------+--------+
9.3.4查询学号是S_1001,S_1002,S_1003的记录(where,in)
写法一:select * from stu where sid = "S_1001" or sid = "S_1002" or sid = "S_1003";
写法二:select * from stu where sid in("S_1001","S_1002","S_1003");
+--------+----------+------+--------+
| sid | sname | age | gender |
+--------+----------+------+--------+
| S_1001 | liuYi | 35 | male |
| S_1002 | chenEr | 15 | female |
| S_1003 | zhangSan | 95 | male |
+--------+----------+------+--------+
9.3.5查询学号不是S_1001,S_1002,S_1003的记录(where,not,in)
select * from stu where sid not in("S_1001","S_1002","S_1003");
9.3.6查询年龄为null的记录(where)
Select * from stu weher age is null;
9.3.7查询年龄在20-40之间的记录(between)
方式一:Select * from stu where age >=20 and <=40;
方式二:Select * from stu where age between 20 and 40;
9.3.8查询性别为非男的记录(where,not)
方式一:Select * from stu where gender !=’male’
方式二:Select * from stu where not gender =’male’
方式三:Select * from stu where gender <> ’male’
9.3.9查询名字不为空的学生信息(is not null)
Select * from stu where sname is not null;
以上是 9.2基础查询 的全部内容, 来源链接: utcz.com/z/535554.html