SQL 查询语句

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

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

 

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

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

     ---  is null 是空                        排序

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

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

    desc 降序 asc升序   若是不写默认为升序排列select

--查询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);
相关文章
相关标签/搜索