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 | zhangsan8 | 1000 |
|  9 | zhangsan9 | 1000 |
| 10 | wang5     | 1000 |
| 11 | wang5%    | 2000 |
| 12 | WANG5     | 1000 |
| 13 | wang5     |  100 |
| 14 | wang5     |  100 |
| 15 | zhangsan7 | 1000 |
| 16 | zhangsan7 | 1002 |
| 17 | zhangsan7 | 1002 |
+----+-----------+------+
15 rows in set (0.03 sec)
时间: 2024-10-13 21:43:36

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

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 (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 (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 (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 |

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 (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; +-----+-------+------------+ |

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基础整理

SQL 是用于访问和处理数据库的标准的计算机语言. 什么是 SQL? SQL 指结构化查询语言 SQL 使我们有能力访问数据库 SQL 是一种 ANSI 的标准计算机语言 编者注:ANSI,美国国家标准化组织  SQL 能做什么? SQL 面向数据库执行查询 SQL 可从数据库取回数据 SQL 可在数据库中插入新的记录 SQL 可更新数据库中的数据 SQL 可从数据库删除记录 SQL 可创建新数据库 SQL 可在数据库中创建新表 SQL 可在数据库中创建存储过程 SQL 可在数据库中创建视图 S