练习题:把good表中商品名为’诺基亚xxxx’的商品,改为’HTCxxxx’,

  • 1,169
1.16 练习题:
把good表中商品名为'诺基亚xxxx'的商品,改为'HTCxxxx',
提示:大胆的把列看成变量,参与运算,甚至调用函数来处理 .
substring(),concat()

mysql> select goods_id,goods_name from goods;
+----------+------------------------------+
| goods_id | goods_name                   |
+----------+------------------------------+
|        1 | kd876                        |
|        4 | 诺基亚n85原装充电器                       |
|        3 | 诺基亚原装5800耳机                      |
|        5 | 索爱原装m2卡读卡器                         |
|        6 | 胜创kingmax内存卡                  |
|        7 | 诺基亚n85原装立体声耳机hs-82                  |
|        8 | 飞利浦9@9v                         |
|        9 | 诺基亚e66                         |
|       10 | 索爱c702c                        |
|       11 | 索爱c702c                        |
|       12 | 摩托罗拉a810                        |
|       13 | 诺基亚5320 xpressmusic            |
|       14 | 诺基亚5800xm                      |
|       15 | 摩托罗拉a810                        |
|       16 | 恒基伟业g101                       |
|       17 | 夏新n7                           |
|       18 | 夏新t5                           |
|       19 | 三星sgh-f258                     |
|       20 | 三星bc01                         |
|       21 | 金立 a30                         |
|       22 | 多普达touch hd                    |
|       23 | 诺基亚n96                         |
|       24 | p806                         |
|       25 | 小灵通/固话50元充值卡                     |
|       26 | 小灵通/固话20元充值卡                     |
|       27 | 联通100元充值卡                       |
|       28 | 联通50元充值卡                        |
|       29 | 移动100元充值卡                       |
|       30 | 移动20元充值卡                        |
|       31 | 摩托罗拉e8                          |
|       32 | 诺基亚n85                         |
+----------+------------------------------+
31 rows in set (0.00 sec)

mysql> select goods_id,goods_name from goods where goods_name like '诺基亚%';
+----------+------------------------------+
| goods_id | goods_name                   |
+----------+------------------------------+
|        4 | 诺基亚n85原装充电器                       |
|        3 | 诺基亚原装5800耳机                      |
|        7 | 诺基亚n85原装立体声耳机hs-82                  |
|        9 | 诺基亚e66                         |
|       13 | 诺基亚5320 xpressmusic            |
|       14 | 诺基亚5800xm                      |
|       23 | 诺基亚n96                         |
|       32 | 诺基亚n85                         |
+----------+------------------------------+
8 rows in set (0.03 sec)

mysql> select goods_id,substring(goods_name,4) from goods where goods_name like
'诺基亚%';
+----------+-------------------------+
| goods_id | substring(goods_name,4) |
+----------+-------------------------+
|        4 | n85原装充电器                   |
|        3 | 原装5800耳机                  |
|        7 | n85原装立体声耳机hs-82              |
|        9 | e66                     |
|       13 | 5320 xpressmusic        |
|       14 | 5800xm                  |
|       23 | n96                     |
|       32 | n85                     |
+----------+-------------------------+
8 rows in set (0.00 sec)

mysql> select goods_id,concat(substring(goods_name,4)) from goods where goods_na
me like '诺基亚%';
+----------+---------------------------------+
| goods_id | concat(substring(goods_name,4)) |
+----------+---------------------------------+
|        4 | n85原装充电器                           |
|        3 | 原装5800耳机                          |
|        7 | n85原装立体声耳机hs-82                      |
|        9 | e66                             |
|       13 | 5320 xpressmusic                |
|       14 | 5800xm                          |
|       23 | n96                             |
|       32 | n85                             |
+----------+---------------------------------+
8 rows in set (0.02 sec)


mysql> select goods_id,concat('htc',substring(goods_name,4)) from goods where go
ods_name like '诺基亚%';
+----------+---------------------------------------+
| goods_id | concat('htc',substring(goods_name,4)) |
+----------+---------------------------------------+
|        4 | htcn85原装充电器                              |
|        3 | htc原装5800耳机                             |
|        7 | htcn85原装立体声耳机hs-82                         |
|        9 | htce66                                |
|       13 | htc5320 xpressmusic                   |
|       14 | htc5800xm                             |
|       23 | htcn96                                |
|       32 | htcn85                                |
+----------+---------------------------------------+
8 rows in set (0.01 sec)

mysql>

 

weinxin
我的微信
这是我的微信扫一扫
开拓者博主
  • 本文由 发表于 2016年5月28日12:46:56
  • 转载请务必保留本文链接:https://www.150643.com/15.html
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: