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;
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341