限定、模糊、排序、多表查询(1)

限定查询基本语法:

select * from 数据表(数据来源) where  过滤条件;

where子句是对数据进行条件判断,选择满足条件的数据。

demo:查询基本工资高于1500的员工

  select * from emp where sal>1500;

demo:根据名字查询信息

  select * from emp where ename='SMITH';

demo:根据职位查数据

  select * from emp where !job='SALLESMAN';

  select * from emp where !job<>'SALLESMAN';

demo:查询工资在1500--3000之间的员工信息

  select * from emp where sal>=1500 and sal<=3000;

  select * from emp where sal between 1500 and 3000;

  以上两种方式使用第二种会更好,第一次被认为是两种判断,第二种被认为是一种判断。所以使用第二种更有效。

demo:查询工资大于2000或者职位是办事人员的信息

  select * from emp where sal>2000

  union all

  select * from where job='CLERK'

  使用union all可以将两个查询结果并在一起显示,一般使用OR来代替或,这样可以避免索引失效

demo:查询所有在1981年入职的员工信息

  select * from emp where hiredate>='01-1月-81' and hiredate<='31-12月-81';

  select * from emp where hiredate between '01-1月-81' and '31-12月-81';

demo:查询出佣金不为空的员工信息

  select * from emp where comm is not null;

demo:查询出佣金为空的员工信息

  select * from emp where comm is null;

demo:查询编号为7369、7765、7788的员工信息

  select * from emp where enpon=7369 or empon=7765 or empon=7788;

  select * from emp where empon in(7369,7765,7788);

demo:查询编号不是7369、7765、7788的员工信息

  select * from emp where enpon<>7369 and empon<>7765 and empon<>7788;

  select * from emp where empon not in(7369,7765,7788);

原文地址:https://www.cnblogs.com/wdss/p/11904803.html