内连接:显示左表及右表符合连接条件的记录,A ∩ B
左外连接:显示左表中的全部和右表符合连接条件的记录,A ∪ (A ∩ B)
右外连接:显示右表中的全部和左表符合连接条件的记录,B ∪ (A ∩ B)
图片:http://oph264zoo.bkt.clouddn.com/17-10-20/73463873.jpg
左外连接:显示左表中的全部和右表符合连接条件的记录,A ∪ (A ∩ B)
右外连接:显示右表中的全部和左表符合连接条件的记录,B ∪ (A ∩ B)
图片:http://oph264zoo.bkt.clouddn.com/17-10-20/73463873.jpg
2017-10-20
分组条件HAVING:
对GROUP BY的查询结果进行过滤
在HAVING字句中,查询对象必须出现在查询表达式中或使用聚合函数
SELECT id, username, age, sex FROM users GROUP BY age HAVING sex = 1;
SELECT username, age, sex FROM users GROUP BY age HAVING count(id) > 0;
对GROUP BY的查询结果进行过滤
在HAVING字句中,查询对象必须出现在查询表达式中或使用聚合函数
SELECT id, username, age, sex FROM users GROUP BY age HAVING sex = 1;
SELECT username, age, sex FROM users GROUP BY age HAVING count(id) > 0;
2017-10-19
SELECT select_expr[, select_expr ...]
[
FROM table_references
[WHERE where_condition]
[GROUP BY {col_name | position} [ASC | DESC], ...]
[HAVING where_condition]
[ORDER BY {col_name | expr | position} [ASC | DESC], ...]
[LIMIT {[offset, ]row_count | row_count OFFSET offset}]
]
[
FROM table_references
[WHERE where_condition]
[GROUP BY {col_name | position} [ASC | DESC], ...]
[HAVING where_condition]
[ORDER BY {col_name | expr | position} [ASC | DESC], ...]
[LIMIT {[offset, ]row_count | row_count OFFSET offset}]
]
2017-10-19
### 删除记录(单表删除)
如果省略WHERE,则该表所有记录都将被删除
DELETE FROM table_name [WHERE where_condition]
### 删除表:
DROP TABLE table_name;
删除没有被关联的普通表:直接上面的SQL语句就行了
删除被其他表关联的父表:
- 方法一:先删除子表,再删除父表
- 方法二:先删除父表的外键约束,再删除父表
如果省略WHERE,则该表所有记录都将被删除
DELETE FROM table_name [WHERE where_condition]
### 删除表:
DROP TABLE table_name;
删除没有被关联的普通表:直接上面的SQL语句就行了
删除被其他表关联的父表:
- 方法一:先删除子表,再删除父表
- 方法二:先删除父表的外键约束,再删除父表
2017-10-19
语法:
UPDATE [LOW_PRIORITY] [IGNORE] table_reference SET col_name1={expr1 | DEFAULT} [, col_name2={expr2 | DEFAULT}]... [WHERE where_condition]
eg:
UPDATE users SET age = age + 5, sex = 2 WHERE username='TOM';
UPDATE [LOW_PRIORITY] [IGNORE] table_reference SET col_name1={expr1 | DEFAULT} [, col_name2={expr2 | DEFAULT}]... [WHERE where_condition]
eg:
UPDATE users SET age = age + 5, sex = 2 WHERE username='TOM';
2017-10-19
基本上都是一天一章,偶尔两章的速度来学的,感受到了老师的满满的教学激情还有其特点,让我知道了数据库的基本基本操作,这次课程大概学了8天。感谢老师的默默讲解。期待下次继续学习
2017-10-18