时间:2021-07-01 10:21:17 帮助过:4人阅读
mysql >select * from t3 where age>30
+-------------+-------------+
|id | age |
+-------------+-------------+
|4 | 56 |
|5 | 62 |
|8 |54 |
|9 |34 |
|10 |36 |
+--------------+-------------+
5 rows in set(0.07 sec)
mysql>secect*from t3 where age>30 and age<50;
+-------------+-------------+
|id | age |
+-------------+-------------+
|9 | 34 |
|10 | 36 |
+-------------+-------------+
排序查询
select*from 表名 order by 字段名【asc/desc】
Asc 由低到高 desc 有高到低
+-------------+-------------+
|id | age |
+-------------+-------------+
|5 | 62 |
|4 | 56 |
|8 | 54 |
|10 | 36 |
|9 | 34 |
|7 |29 |
|3 |26 |
|6 |21 |
|2 |21 |
|1 |20 |
+--------------+-------------+
限制查询
select * from t3 limit 2,5
+-------------+-------------+
|id | age |
+-------------+-------------+
|3 | 26 |
|4 | 56 |
|5 | 62 |
|6 |21 |
|7 |29 |
+-------------+-------------+
mysql >select *from t3 limit 5;
+-------------+-------------+
|id | age |
+-------------+-------------+
|1 | 20 |
|2 | 21 |
|3 | 26 |
|4 |56 |
|5 |62 |
+-------------+-------------+
删除所有 删除记录
Delete from 表名
按条件删 delete from 表名 where 条件表达式
mysql> delete from t3 where id=3;
Query OK, 1 row affected (0.06 sec)
mysql > select * from t3;
+-------------+-------------+
|id | age |
+-------------+-------------+
|1 | 12 |
|2 | 12 |
|4 |12 |
|5 |62 |
|6 |56 |
+-------------+-------------+
改数据
Update 表名 set 字段=值
如果不带条件 会把字段下面的记录全改
mysql> update t3 set age=12;
Query OK, 10 rows affected (0.07 sec)
Rows matched : 10 Changed : 10 Warnings:
mysql >select * from t3;
+-------------+-------------+
|id | age |
+-------------+-------------+
|1 |12 |
|2 | 12 |
|3 | 12 |
|4 | 12 |
|5 | 12 |
|6 |12 |
|7 |12 |
|8 |12 |
|9 |12 |
|10 |12 |
+--------------+-------------+
按条件更新
mysql >update t3 set age=56 where id = 6;
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed : 1 Warnings:0
mysql>select * from t3;
+-------------+-------------+
|id | age |
+-------------+-------------+
|1 |12 |
|2 | 12 |
|3 | 12 |
|4 | 12 |
|5 | 12 |
|6 |56 |
|7 |12 |
|8 |12 |
|9 |12 |
|10 |12 |
+--------------+-------------+
Mysql指令
标签:语法 root ash -- 创建数据库 进入 sele query roo