sql 基础--mysql 5 (10)

17.更新和删除数据

更新: update table set columns =  ‘value’ where ...

mysql> update pw_price set price=10000 where uid=6;
Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from pw_price;
+-----+-------+------------+
| uid | price | first_name |
+-----+-------+------------+
|   1 |   100 | wang       |
|   2 |  1000 | zhang      |
|   3 |  2000 | li         |
|   4 |  5000 | weizhi     |
|   5 |  5000 | cai        |
|   6 | 10000 | guo        |
+-----+-------+------------+
6 rows in set (0.00 sec)
mysql> update pw_price set first_name="guo6" where uid = 6;
Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from pw_price;
+-----+-------+------------+
| uid | price | first_name |
+-----+-------+------------+
|   1 |   100 | wang       |
|   2 |  1000 | zhang      |
|   3 |  2000 | li         |
|   4 |  5000 | weizhi     |
|   5 |  5000 | cai        |
|   6 | 10000 | guo6       |
+-----+-------+------------+
6 rows in set (0.00 sec)

删除数据

delete from table where 。。。

mysql> select * from pw_price;
+-----+-------+------------+
| uid | price | first_name |
+-----+-------+------------+
|   1 |   100 | wang       |
|   2 |  1000 | zhang      |
|   3 |  2000 | li         |
|   4 |  5000 | weizhi     |
|   5 |  5000 | cai        |
|   6 | 10000 | guo6       |
+-----+-------+------------+
6 rows in set (0.00 sec)

mysql> delete from pw_price where uid >=6;
Query OK, 1 row affected (0.03 sec)

mysql> select * from pw_price;
+-----+-------+------------+
| uid | price | first_name |
+-----+-------+------------+
|   1 |   100 | wang       |
|   2 |  1000 | zhang      |
|   3 |  2000 | li         |
|   4 |  5000 | weizhi     |
|   5 |  5000 | cai        |
+-----+-------+------------+
5 rows in set (0.00 sec)
时间: 2024-10-13 21:43:38

sql 基础--mysql 5 (10)的相关文章

sql 基础--mysql 5 (6)

12.子查询 子查询进行过滤 mysql> select msg from pw_luck where name = 'wang5' -> ; +------+ | msg | +------+ | 1001 | | 1000 | | 1000 | | 100 | | 100 | +------+ 5 rows in set (0.03 sec) mysql> select uid from pw_luck where msg in (select msg from pw_luck wh

sql 基础--mysql 5 (5)

10.汇总数据 聚集函数 avg平均值,count行数,max最大值,min最小值,sum之和 mysql> select msg,avg(msg) from pw_luck; +-----+----------+ | msg | avg(msg) | +-----+----------+ | 100 | 920.2000 | +-----+----------+ 1 row in set (0.00 sec) mysql> select msg,sum(msg) from pw_luck;

sql 基础--mysql 5 (3)

8.计算字段 concat () 拼接串 mysql> select concat (name,'-',msg) from pw_luck; +-----------------------+ | concat (name,'-',msg) | +-----------------------+ | Wilson-100 | | zhangsan-100 | | lisi-1001 | | wang5-1001 | | zhangsan7-1000 | | zhangsan8-1000 | |

sql 基础--mysql 5 (4)

9.数据处理函数 文本处理:Upper 大写 mysql> select uid,name,msg, Upper(name) as UpperName from pw_luck; +-----+-----------+------+-----------+ | uid | name | msg | UpperName | +-----+-----------+------+-----------+ | 0 | Wilson | 100 | WILSON | | 1 | zhangsan | 10

sql 基础--mysql 5 (7)

14.高级联结表 使用别名 mysql> select uid as u,name as n,msg as m from pw_luck; +----+-----------+------+ | u | n | m | +----+-----------+------+ | 0 | Wilson | 100 | | 1 | zhangsan | 100 | | 2 | lisi | 1001 | | 3 | wang5 | 1001 | | 7 | zhangsan7 | 1000 | | 8

sql 基础--mysql 5 (8)

15.组合查询 union mysql> select uid,first_name,price from pw_price where uid >2 union select uid,first_name,price from pw_price where price>=1000; +-----+------------+-------+ | uid | first_name | price | +-----+------------+-------+ | 3 | li | 2000

sql 基础--mysql 5 (9)

16 插入 insert into table values() mysql> insert into pw_price values (5,5000,'cai'); Query OK, 1 row affected (0.03 sec) mysql> select * from pw_price;+-----+-------+------------+ | uid | price | first_name | +-----+-------+------------+ | 1 | 100 |

sql 基础--mysql 5

mysql5.6 安装 http://jingyan.baidu.com/article/f3ad7d0ffc061a09c3345bf0.html md中输入:net start mysql,服务启动成功 mysql -u root -p(第一次登录没有密码,直接按回车过),登录成功! mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema |

MySQL,Oracle,SQL Server——选取前10条——语法差异

前言 今天,用select top 10 * from table;在mysql上报错. 原因 实现选取前10条,不同数据库存在差异. 描述 MySQL select * from table1 limit 10 #具体语法: select * from table1 limit m,n; #从m开始选取n条. SQL Server select top 10 * from table Oracle select * from table where rownum<=10