- 插入记录
语法:INSERT [INTO] [(tbl_name,...)] {VALUE|VALUE} ({expr|DEFAULT},...),(...),...
例子:
给所有的列都插入数据
INSERT student VALUES('1','Tom','123')
给某几个列插入数据
INSERT student(sname) VALUES('Tom');
- 更新记录(单表更新)
语法:UPDATE [LOW_PRIORITY] [IGNORE] table_reference SET
col_name1={expr1|DEFAULT} [,col_name2={expr2|DEFAULT}]...
[WHERE where_condition]
例子:
1.将所有人的年龄更新为25岁
UPDATE student SET age = '25';
2.将sid=1的年龄改为30岁
UPDATE student SET age='30';
- 删除记录(单表删除)
语法:DELETE FROM tbl_name [WHERE where_condition]
例子:DELETE FROM tbl_name WHERE sid='1';
- 查询记录
基本语法:
SELECT select_expr [,select_expr];
注:*代表所有列
- 查询结果分组
语法:[GROUP BY {col_name|position}[ASC|DESC],...]
例子:SELECT sex FROM student GROUP BY sex;
- 分组条件
语法:[HAVING where_condition]
例子:SELECT sex FROM student GROUP BY sex HAVING count(id)>=2
输出人数大于等于2的性别
- 对查询结果进行排序
语法:[ORDER BY {col_name | expr | position} [ASC|DESC],...]
- 限制查询结果返回的数量
语法:[LIMIT {[offset,]}] row_cout | row_count OFFSET offset}]
例子:SELECT sname FORM student LIMIT 1,2;
从第二条开始选取两个(开始位置从0开始)
posted @
2014-11-19 17:45
calmound
阅读(
168)
评论()
编辑
收藏
举报