select模型

可以把列看成变量,变量时可以运算的

select goods_id,goods_name,(market_price-shop_price) as discount from goods where cat_id=3;

discount是临时创建的一个列,可以打印出来

 

如果想查出本店价比市场价便宜200的  语句如下

select goods_name,(market_price-shop_price) as discount from goods where (market_price-shop_price)>200;

其中只能使用(market_price-shop_price)>200,而不能使用discount>200,因为discount是临时的

因为语句开始执行,则where开始发挥作用,然后才生成discount,所以能用discount在where语句中

 

对于结果中的筛选只能用having

 

 

+------+
| num  |
+------+
|    3 |
|   12 |
|   15 |
|   25 |
|   23 |
|   29 |
|   34 |
|   37 |
|   32 |
|   45 |
|   48 |
|   52 |
+------+

对于23 25 29 改成20  34 37 32 改成30

思路,对于他们分别取整 ,然后再分别乘以10

mysql> update mian set num=floor(num/10)*10
    -> where num>=20 and num<=39;
posted @ 2013-11-20 02:31  long896130895  阅读(131)  评论(0)    收藏  举报