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  |  100 | ZHANGSAN  |
|   2 | lisi      | 1001 | LISI      |
|   3 | wang5     | 1001 | WANG5     |
|   7 | zhangsan7 | 1000 | ZHANGSAN7 |
|   8 | zhangsan8 | 1000 | ZHANGSAN8 |
|   9 | zhangsan9 | 1000 | ZHANGSAN9 |
|  10 | wang5     | 1000 | WANG5     |
|  11 | wang5%    | 2000 | WANG5%    |
|  12 | WANG5     | 1000 | WANG5     |
+-----+-----------+------+-----------+
10 rows in set (0.02 sec)

  文本处理:Soundex匹配所有发音类似的项

mysql> select uid,name,msg, Upper(name) from pw_luck where Soundex(name)=Soundex(‘wangwu‘);
+-----+--------+------+-------------+
| uid | name   | msg  | Upper(name) |
+-----+--------+------+-------------+
|   3 | wang5  | 1001 | WANG5       |
|  10 | wang5  | 1000 | WANG5       |
|  11 | wang5% | 2000 | WANG5%      |
|  12 | WANG5  | 1000 | WANG5       |
+-----+--------+------+-------------+
4 rows in set (0.03 sec)

  日期和时间处理函数

    Data() 2012-12-12

    Year()  2012

    Mounth() 2

  数值处理: Abs绝对值 Cos余弦 Exp指数 Mod余数 Sqrt平方根

mysql> select name,msg,Sqrt(msg) from pw_luck;
+-----------+------+--------------------+
| name      | msg  | Sqrt(msg)          |
+-----------+------+--------------------+
| Wilson    |  100 |                 10 |
| zhangsan  |  100 |                 10 |
| lisi      | 1001 |  31.63858403911275 |
| wang5     | 1001 |  31.63858403911275 |
| zhangsan7 | 1000 | 31.622776601683793 |
| zhangsan8 | 1000 | 31.622776601683793 |
| zhangsan9 | 1000 | 31.622776601683793 |
| wang5     | 1000 | 31.622776601683793 |
| wang5%    | 2000 | 44.721359549995796 |
| WANG5     | 1000 | 31.622776601683793 |
+-----------+------+--------------------+
10 rows in set (0.02 sec)

  

时间: 2024-10-29 19:12:07

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

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

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