Select .从指定表中取出指定的列的数据
- 选出字段名” LastName”、” FirstName” 的数据
SELECT LastName,FirstName FROM Persons
Where .被用来规定一种选择查询的标准
- 从” Persons”表中选出生活在” Sandnes” 的人
SELECT * FROM Persons WHERE City='Sandnes'
And & Or .在WHERE子句中AND和OR被用来连接两个或者更多的条件
- 用AND运算子来查找"Persons" 表中FirstName为”Tove”而且LastName为” Svendson”的数据
SELECT * FROM Persons
WHERE FirstName='Tove'
AND LastName='Svendson'
- 用OR运算子来查找"Persons" 表中FirstName为”Tove”或者LastName为” Svendson”的数据
SELECT * FROM Persons
WHERE firstname='Tove'
OR lastname='Svendson'
- 结合AND和OR (使用括号形成复杂的表达式)
SELECT * FROM Persons WHERE
(FirstName='Tove' OR FirstName='Stephen')
AND LastName='Svendson'
Between…And .指定需返回数据的范围
- 用BETWEEN…AND返回LastName为从”Hansen”到”Pettersen”的数据
SELECT * FROM Persons WHERE LastName
BETWEEN 'Hansen' AND 'Pettersen'
- 显示指定范围之外的数据,也可以用NOT操作符
SELECT * FROM Persons WHERE LastName
NOT BETWEEN 'Hansen' AND 'Pettersen'
Distinct .DISTINCT关键字被用作返回唯一的值
- 用DISTINCT关键字返回Company字段中唯一的值
SELECT DISTINCT Company FROM Orders
Order by .指定结果集的排序
- 按照Company字段的升序方式返回结果集
SELECT Company, OrderNumber FROM Orders
ORDER BY Company
- 按照Company字段的降序方式返回结果集
SELECT Company, OrderNumber FROM Orders
ORDER BY Company DESC
Group by.对结果集进行分组,常与汇总函数一起使用
- 按照Company字段进行分组,求出每个Company的Amout的合计
SELECT Company,SUM(Amount) FROM Sales
GROUP BY Company
Having .指定群组或汇总的搜寻条件
- 按照Company字段进行分组,求出每个Company的Amout的合计在10000以上的数据
SELECT Company,SUM(Amount) FROM Sales
GROUP BY Company HAVING SUM(Amount)>10000
Join .从两个或者以上的表中选取结果集时,你就会用到JOIN
- 用Employees的ID和Orders的ID相关联选取数据
SELECT Employees.Name, Orders.Product
FROM Employees, Orders
WHERE Employees.ID = Orders.ID
Alias .可用在表、结果集或者列上,为它们取一个逻辑名称
- 给列取别名
SELECT LastName AS Family, FirstName AS Name
FROM Persons
Insert Into .在表中插入新行
- 插入一行数据
INSERT INTO Persons
VALUES ('Hetland', 'Camilla', 'Hagabakka 24', 'Sandnes')
Update .更新表中原有数据
- 将Person表中LastName字段为”Rasmussen”的FirstName更新为”Nina”
UPDATE Person SET FirstName = 'Nina'
WHERE LastName = 'Rasmussen'
Delete .删除表中的数据
- 删除Person表中LastName为”Rasmussen”的数据
DELETE FROM Person WHERE LastName = 'Rasmussen'
【数据库功能】http://shouce.jb51.net/sql.html
推荐阅读
- mysql|InnoDB数据页结构
- javaweb|基于Servlet+jsp+mysql开发javaWeb学生成绩管理系统
- mysql|一文深入理解mysql
- Java毕业设计项目实战篇|Java项目:在线嘿嘿网盘系统设计和实现(java+Springboot+ssm+mysql+maven)
- SQL|SQL基本功(五)--函数、谓词、CASE表达式
- vue|电商后台管理系统(vue+python|node.js)
- Java及基础算法及数据结构|旧笔记整理(MySQL)
- mysql|双非本211硕,无实习无项目,自学大数据开发,秋招上岸
- 数据库|Mysql--InnoDB存储引擎详解
- MySQL学习笔记-9-order by