SQL 查询语句

基本查询语句: select */列1,列2... from 表名

条件查询(过滤查询): select */列1,列2... from 表名 where 条件s

 

  • 条件中可以使用的运算符:
  1. 算数(比较)运算符:> , >= , < , <= , <> , != , =
  2. 逻辑运算符:not , and , or       (and 优先级高于or 可以通过括号改变优先级)
  3.  ---in(多个值) 在...之中,进行的是等值比较                

     --- between...and...在某个取值范围之间          

     ---  is null 是空                        

       --- like 模糊查询(_代表1个字符  %代表n个字符)

--查询emp表中名字的最后一个字为'花'的员工信息
select * from emp where ename like '%花';
--查询emp表中名字的最后一个字为'花'且名字为两个字的员工信息
select * from emp where ename like '_花';
  • 排序  order by列名 desc/asc 

    desc 降序 asc升序   如果不写默认为升序排列

--查询20号部门的员工 并且员工的工资大于1000 按照员工的编号的降序排序显示
select * from emp where deptno=20 and sal>1000 order by empno desc;
--查询员工信息中管理者不为null的员工中,员工为10号部门员工或者查询绩效为null并且工资大于2000的员工
select * from emp where mgr is not null and (deptno=10 or comm is null and sal>2000);

 

posted on 2017-05-10 19:55  木杉彬彬彬  阅读(108)  评论(0编辑  收藏  举报