【01】Oracle数据库_SQL基础查询
一、SQL基础查询_简单查询
- 简单查询的基本操作格式
-
select t.* from emp t; - 别名的设置
-
select t.empno, t.job, t.sal from emp; - 在简单查询之中实现四则运算与字符串的连接显示
-
select distinct t.job from emp t ; #去重 如果查询多个列,只有在多个列都相同时,才会消除
select empno , empname , sal*12 income from emp #年薪=月薪*12后字段重新命名
-
select '雇员编号:'|| empno||',姓名:'||empname from emp #||负责进行输出的内容对的连接,很少用 #别名不需要用“ ' ”声明
总结:select 查询时,设置常量要注意:
1、如果常量是字符串,则要求使用“ ‘ ’”声明
2、如果常量是数字,则直接编写
3、如果常量是日期,则按照日期风格格式编写
二、SQL基础查询_限定查询
关系运算符:>、<、>=、<=、<>(!=);
-
select * from emp where empname = 'SAM' and sal =1500 ;
逻辑运算符:and 、or 、not;
-
select * from emp where empname = 'SAM' or sal =1500 ;
范围运算符:between …and;
-
select * from emp where sal beween 200 and 300 ;
#在此最小值(包含最少值)与最大值(包含最大值)之间的内容都满足条件
谓词运算符:in 、not in;
-
select * from emp where empname not in ('SAM','JIM','TOM');
#如果范围里面包含有null,那么就不能用not in
空判断:is null 、is not null;
-
select * from emp where sal is not null ; #如果在数字列上使用 null 那么绝对不表示0,空的操作只能用 is null 和is not null表示
模糊查询:like;
-
select * from emp where empname like '%A%'; select * from emp where empname like '_A%'; #"_": 表示匹配任意的一位字符; #“%”:表示匹配任意的零位、一位或多位字符;
三、SQL基础查询_查询排序
-
#升序 select * from emp where empname like '%A%' order by sal ; #多条件排序 select * from emp where empname like '%A%' order by sal desc,date asc;
浙公网安备 33010602011771号