SQL学习总结(二)

select 语句加where子句(条件限制)

1.Limiting Rows using a Selection
  select * from emp where deptno=30;
  select * from emp where ename='KING';
2.Comparison conditions
   select * from emp where sal>2500;
3.Other Comprison conditions
  a)using BETWEEN
    select * from emp where sal between 900 and 2000;
  b)using IN 
    select * from emp where mgr in(7698,7788);
  c)using LIKE(%可以代表任意多个字符,而_代表任一字符)
    select * from emp where ename like 'A%';
    select * from emp where ename like '_A%';
  d)using NULL
     select * from emp where mgr is null;
4. logical conditions
  a) using the AND operator
         select * from emp where  sal>1000 and job like '%MAN%';

  b) using the OR operator
         select * from emp where  sal>1000 and job like '%MAN%';

  c) using the NOT operator
         select * from emp where job not in ('SALESMAN','CLERK');
5.Rules of Precedence (注意下面两种情况是不同的)
     select * from emp where job='SALESMAN' or job='CLERK'  and sal >=1300;
     select * from emp where (job='SALESMAN' or job='CLERK')  and sal >=1300;

ORDER BY子句 默认的是按asc排序
 
1. select * from emp order by hiredate;

2. sorting in descending order
     select * from emp order by hiredate desc;

3. sorting by column alias
     select ename,sal,12*sal annsal from emp order by annsal;

4. sorting by multiple columns
     select ename,deptno,sal annsal from emp order by deptno,sal desc;
    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值