SQL COOKBOOK SQL经典实例代码 笔记第一章代码
2024-10-08 16:59:42
-- 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')
最新文章
- [LeetCode] Consecutive Numbers 连续的数字
- 图解TCP-IP协议
- SQL Server调优系列基础篇
- Deis logo 开源PaaS系统 Deis
- ASP.NET MVC 5 局部视图不支持异步问题
- PZISP自动下载软件运行时出现“应用程序无法启动,因为应用程序的并行配置不正确”
- web压力测试的轻量级具体做法
- 获取随机颜色js
- Java垃圾回收初步理解
- 用vue开发一个app(3,三天的成果)
- js单元测试
- Log print(Android)
- mybatis 插入数据 在没有commit时 获取主键id
- es6在项目中的应用
- noip 2013 提高组 day1
- CSS样式表的写作规范
- 小米推送 简介 集成 MD
- 31. centos 下修改oracle的编码
- padding 扩大边距 margin-top 与页面顶部的距离 hover鼠标移动到上面出现背景色CSS
- Intelj IDEA的pom.xml显示错误can not reconnect
热门文章
- P1091 N-自守数
- TCP为什么三次握手四次挥手
- C++中数字与字符串之间的转换 scanf string总结(复习必读)
- LabVIEW面向对象的ActorFramework(1)
- PreparedStatement 和 Statement 的区别(推荐使用PreparedStatement)
- 063、Java中输出信息
- 007.Delphi插件之QPlugins,插件的卸载和重新加载
- 微信小程序提示:https://api.map.baidu.com 不在以下 request 合法域名列表中
- 修正png
- 用QEMU模拟运行uboot从SD卡启动Linux