当前位置:网站首页>SQL 速查
SQL 速查
2020-11-08 16:57:00 【程序猿欧文】

- 关系数据库,基于关系模型,使用关系(表)存储数据,同时定义了完整性约束。常见的关系数据库系统包括:Oracle、MySQL/MariaDB、SQL Server、PostgreSQL 等等。
- SQL,结构化查询语言,访问和操作关系数据库的标准语言。SQL 具有声明性,是一种面向集合的编程语言。
1、单表查询
SELECT col1, col2 AS c2 -- 列别名 FROM t; -- 基本查询SELECT * FROM t; -- 查询所有字段SELECT col1, col2, … FROM t WHERE conditions; -- 过滤条件SELECT col1, col2, … FROM t ORDER BY col1 ASC, col2 DESC; -- 排序SELECT col1, col2, … FROM t ORDER BY col1 ASC, col2 DESC OFFSET m ROWS FETCH FIRST n ROWS ONLY; -- 限定数量 LIMIT n OFFSET m; -- 非标准实现SELECT col1, col2, agg_fun() -- 聚合函数 FROM t GROUP BY col1, col2 -- 分组汇总 HAVING conditions; -- 分组后过滤
2、多表连接
SELECT t1.col1, t2.col2, … FROM t1 INNER JOIN t2 ON conditions; -- 内连接 SELECT t1.col1, t2.col2, … FROM t1 LEFT JOIN t2 ON conditions; -- 左连接SELECT t1.col1, t2.col2, … FROM t1 RIGHT JOIN t2 ON conditions; -- 右连接SELECT t1.col1, t2.col2, … FROM t1 FULL JOIN t2 ON conditions; -- 全连接SELECT t1.col1, t2.col2, … FROM t1 CROSS JOIN t2 ON conditions;-- 交叉连接SELECT a.col1, b.col2, … FROM t1 a -- 表别名 JOIN t1 b ON conditions; -- 自连接
3、集合运算
SELECT col1, col2, … FROM t1 UNION [ALL]SELECT c1, c2, … FROM t2; -.........
版权声明
本文为[程序猿欧文]所创,转载请带上原文链接,感谢
https://my.oschina.net/mikeowen/blog/4708273
边栏推荐
- What are the necessary laws and regulations to know when entering the Internet?
- Golang ICMP协议探测存活主机
- Is there no way out for older programmers?
- [open source]. Net uses ORM to access Huawei gaussdb database
- 函数分类大pk!sigmoid和softmax,到底分别怎么用?
- Flink's sink: a preliminary study
- Recurrence of Apache kylin Remote Code Execution Vulnerability (cve-2020-1956)
- python开发qt程序读取图片的简单流程
- 前后端分离跨域问题解决方案
- On the concurrency of update operation
猜你喜欢
Millet and oppo continue to soar in the European market, and Xiaomi is even closer to apple
我用 Python 找出了删除我微信的所有人并将他们自动化删除了
One minute comprehensive understanding of forsage smart contract global shared Ethereum matrix plan
vim-配置教程+源码
Improvement of rate limit for laravel8 update
Station B STM32 video learning
Examples of unconventional aggregation
契约式设计(Dbc)以及其在C语言中的应用
Exercise 5
佛萨奇forsage以太坊智能合约是什么?以太坊全球滑落是怎么回事
随机推荐
总结: 10月海外DeFi新项目,更多资管策略来了!
我用 Python 找出了删除我微信的所有人并将他们自动化删除了
LiteOS-消息队列-实战
Apache Kylin远程代码执行漏洞复现(CVE-2020-1956)
Builder pattern
Tips and skills of CSP examination
read文件一个字节实际会发生多大的磁盘IO?
Arduino ide build esp8266 development environment, slow file download solution | esp-01 make WiFi switch tutorial, transform dormitory lights
Talk about go code coverage technology and best practices
趣文分享:C 语言和 C++、C# 的区别在什么地方?
The first open source Chinese Bert pre training model in the financial field
机械硬盘随机IO慢的超乎你的想象
CSP考试须知与各种小技巧
Mac环境安装Composer
TypeScript(1-2-2)
佛萨奇forsage以太坊智能合约是什么?以太坊全球滑落是怎么回事
Liteos message queuing actual combat
AI周报:允许“员工自愿降薪”;公司回应:员工内心高兴满意;虎牙HR将员工抬出公司;瑞典禁用华为中兴5G设备
苏州游记
小青台正式踏上不归路的第3天