简单的where子句
使用where条件进行结果筛选
语法:select * from 表名 where 条件;注意:条件中字段值区分大小写,字段名不区分大小写,字段值使用单引号括起来
1、在where中使用算术表达式 = ,< , > ,>= ,<= ,<>
2、使用order by 对筛选结果进行排序,order by 出现在where后面
查看工资等于1250的员工信息
select * from emp where sal='1250'--筛选条件是个数字也可以使用单引号
查看工作等于CLERK的员工信息
select * from emp where job='CLERK'--在筛选条件中字段值如果是字符需要加上单引号
select * from emp where job='clerk'--在sql语句中字段的值是区分大小写的
select * from emp where JOB='CLERK'--在sql中字段是不区分大小写的
查看工资大于1250的员工姓名和工作
select ename,job ,sal from emp where sal>'1250' order by sal--使用order by 对筛选结果进行排序,order by 出现在where后面
查看工资大于等于2000的员工信息
select * from emp where sal>=2000;
查看工资小于等于2000的员工信息;
select * from emp where sal<=2000
查看工资不等于1500的员工信息
select * from emp where sal<>1500 order by sal
查看入职日期在81年后的员工信息
select * from emp where hiredate>'1981年12月31号'
select * from emp where hiredate>'1981/12/31'
select * from emp where hiredate>'31-12月-1981'--使用日期的默认格式查询符合要求的数据,日-月-年
where子句使用关键字
使用where子句进行结果的筛选
知识点:where查询条件中使用关键字
1、and 用于多条件的与筛选:select * from 表名 where 条件 and 条件 and 条件....
2、or 用于多条件的或筛选: select * from 表名 where 条件 or 条件 or 条件....
3、in 用于多条件的或筛选: select * from 表名 where 字段名 in(值,值,值....)
4、like用于模糊查询: select * from 表名 where 字段名 like '%值%' 包含
5、is null 和is not null 用来判断字段是否为空 select * from 表名 where 字段名 is null
讲解: 在where子句中使用关键字
--查询工资在2000-3000之间的员工信息
select * from emp where sal>=2000 and sal<=3000--使用and关键字进行"与"的多条件筛选;
select * from emp where sal between 2000 and 3000;--使用between and 关键字进行筛选;
--查询工作为SALESMAN,ANALYST,MANAGER的员工信息
select * from emp where job='SALESMAN' or job='ANALYST' or job='MANAGER'--使用or关键字进行"或"的多条件筛选
select * from emp where job in('SALESMAN','ANALYST','MANAGER');--使用in关键字进行"或"的多条件筛选
select * from emp where job='ANALYST'
--查询姓名中包含s的,以s开头的,以s结尾的,第二个字符为A的。
select * from emp where ename like '%S%';--使用like关键字,姓名中包含S的,%代表任意多个字符
select * from emp where ename like 'S%';--使用like关键字,以S开头的
select * from emp where ename like '%S';--以S结尾的
select * from emp where ename like '_A%'--使用"_"指定位置包含指定字符的信息,"_"代表任意一个字符
--------------查询名字中包含下划线的用户信息
select * from emp where ename like '%A_%'escape 'A';--使用escape关键字将普通字符设置成为转译字符。
--查询有津贴的员工信息
select * from emp where comm is not null;
select * from emp where comm is null;--查询没有津贴的员工信息
oracle数据库操作中简单的where子句及where子句关键字
最新推荐文章于 2023-03-01 15:52:29 发布