-- SQL COOKBOOK CHAPTER1
-- 查看所有内容
select * from emp; -- 可以单列
select empno,ename,job,sal,mgr,hiredate,comm,deptno
from emp; -- 设定条件
select * from emp
where deptno=10; -- 条件可以用逻辑运算符连接
select * from emp
where deptno=10
or comm is null
or sal<=2000
and deptno=20; -- 注意括号和顺序
select * from emp
where (
deptno=10
or comm is not null
or (deptno=20 and sal<=2000)
); -- 起有意义的别名
select sal as salary, comm as commission from emp; -- 使用子查询可以在条件中用别名筛选
select * from
(
select sal as salary, comm as commission
from emp
)x
where salary<5000; -- 代码执行的顺序:from -> where -> select select ename, job
from emp
where deptno=10; -- 连接符号
select ename||' WORKS AS A '||job as msg
from emp where deptno=10;
-- || 是concat的快捷方式
select concat(ename,' WORKS AS A ', job) FROM EMP where deptno=10; -- case when
select ename,sal,
case when sal<=2000 then 'UNDERPAID'
when sal>=4000 then 'OVERPAID'
ELSE 'OK'
end as status
from emp; -- 取前5行
select * from emp limit 5;
-- 任意序列的前5行
select ename, job from emp order by random() limit 5; -- 查询空值
select * from emp where comm is null;
-- 空值置换
select coalesce(comm, 0) from emp;
-- in的使用
select ename,job,deptno from emp where deptno in (10, 20);
-- like的使用
select ename,job from emp where deptno in (10,20) and (ename like '%I%' or job like '%ER')

最新文章

  1. [LeetCode] Consecutive Numbers 连续的数字
  2. 图解TCP-IP协议
  3. SQL Server调优系列基础篇
  4. Deis logo 开源PaaS系统 Deis
  5. ASP.NET MVC 5 局部视图不支持异步问题
  6. PZISP自动下载软件运行时出现“应用程序无法启动,因为应用程序的并行配置不正确”
  7. web压力测试的轻量级具体做法
  8. 获取随机颜色js
  9. Java垃圾回收初步理解
  10. 用vue开发一个app(3,三天的成果)
  11. js单元测试
  12. Log print(Android)
  13. mybatis 插入数据 在没有commit时 获取主键id
  14. es6在项目中的应用
  15. noip 2013 提高组 day1
  16. CSS样式表的写作规范
  17. 小米推送 简介 集成 MD
  18. 31. centos 下修改oracle的编码
  19. padding 扩大边距 margin-top 与页面顶部的距离 hover鼠标移动到上面出现背景色CSS
  20. Intelj IDEA的pom.xml显示错误can not reconnect

热门文章

  1. P1091 N-自守数
  2. TCP为什么三次握手四次挥手
  3. C++中数字与字符串之间的转换 scanf string总结(复习必读)
  4. LabVIEW面向对象的ActorFramework(1)
  5. PreparedStatement 和 Statement 的区别(推荐使用PreparedStatement)
  6. 063、Java中输出信息
  7. 007.Delphi插件之QPlugins,插件的卸载和重新加载
  8. 微信小程序提示:https://api.map.baidu.com 不在以下 request 合法域名列表中
  9. 修正png
  10. 用QEMU模拟运行uboot从SD卡启动Linux