Oracle in SQL01

Single-table queries

* from emp the SELECT;
- a lookup table in the specified field values
the SELECT empno, ename from emp;
the SELECT empno from emp;
- fields in query results using an alias
- Use keyword field name as "Alias" in the field
- note: as keywords can be omitted, alias no special characters in double quotation marks omitted
select empno employee number, ename "employee name", job as work, mgr as "no wisdom for leadership" from emp;
- connectors: field name || ' character '|| ... from table name field name
- || connector for the SQL statement, and only select between from
- Note: a spliced connection in the result set is displayed as a new field, you can use the alias optimization
select empno || 'name is' || ename as "information" from emp;
the SELECT the job || 'ha ha' || mgr as "work information" from emp;
- removing duplicate: use distinct field names, field names. . . from table
- Note: remove duplicate rules are in accordance with the removal of the line, a multi-line data duplication whichever
the SELECT DISTINCT the Job, MGR from emp;
- sorting select * from table name order by field name asc asc Ascending Ascending not write
-select descending desc
- multi-field sorting
-Select * from emp order by field name 1, field name 2 .. .
- sorted first according to a field, the value 1 if the field is the same then the two field values
SELECT * from EMP EMPNO Order by DESC;
SELECT Job, EMPNO from EMP EMPNO Order by ASC;
SELECT * from EMP Order by EMPNO, ename;
- logical operation field
SELECT * from EMP;
SELECT EMPNO, ename, Job, SAL + 1000, SAL + COMM from EMP;

  --查询国有员工的工资信息
  select empno,ename,sal+comm as "薪资" from emp
  --查询SMYH的个人信息
  select * from emp where ename = 'SMITH';
  --查询SMTH的信息信息,逻辑运算符
  select empno,ename,sal+comm from emp where ename = 'SMITH';
  --查询工资大于1000员工的信息
  select * from emp where sal>1000;
  --查询工资不等于3000的员工信息
  select * from emp where sal <> 3000;
  --练习 
     --查看工资等于1250员工的信息
  select * from emp where sal = 1250;
     --查看工作等于CLERK员工的信息
   select * from emp where job='CLERK';
   --查看工资大于1250的员工姓名和工作
   select ename,job from emp where sal>1250;
   --查看工资大于等于2000的员工信息
   select * from emp where sal >2000;
   --查看入职日期在81年后的员工信息
     --注意:Oracle默认的日期格式 日-月-年 '03-1月-1981'
     select * from emp order by hiredate;
     select * from emp where hiredate>='01-1月-1981'order by hiredate;
     
   --------多条筛选(where子句关键字 and,or,is,null,is not null,in,between and)
   --查询有津贴的员工信息 字段名 is null 字段值为null
   -- is not null 字段值不为null
   --多个条件使用and进行连接,筛选的符合所有条件的数据
      --select * from 表名 where 筛选条件1and2
     select * from emp where comm is not null and comm>0;
   
   --查询姓名中包含S的,以S开头的,以S结尾的,第二个字符为A的 LIKE关键字(模糊查询)
        --使用模糊查询 select * from 表名 where 字段名 like '%字符%' 查询指定字符的数据
        --%表示任意多个字符
      select * from emp where ename like '%S%';--包含S, 
      select * from emp where ename like 'S%'--yi S开头
      select * from emp where ename like '%S'--S jie wei de 
      select * from emp where ename like '_A%';--  (_) 表示一个字符
      select * from emp where ename like '%/_%' escape '/'
      --select * from 表名 where 字段名  like '%字符2字符1%' escape '字符2'
               --escape将指定的字符变为转义字符,转义字符可以将特殊字符转为普通字符
      select * from emp for update
      --查询工作为SALESMAN,ANALYST,MANAGER的员工信息
        --s使用or进行条件或筛选
      SELECT * from emp where job='SALESMAN' or job='ANALYST' or job='MANAGER';
        --使用in关键字,也可以筛选,但是in中的内容只能为一个字段的值。
      select * from emp where job in('SALESMAN','ANALYST','MANAGER');
      --查询工资在2000-3000之间的
      select * from emp where sal<2000 and sal>1000;
      --使用between and关键字 包含两头的数据
      select * from emp where sal between 2000 and 3000;
Released six original articles · won praise 0 · Views 29

Guess you like

Origin blog.csdn.net/weixin_43421717/article/details/104256386