mysql的select語句寫計算公式

沒有公式的select

mysql> select * from t_bt_strategy a where strategyid=2 and buyprice<sellprice;
+-------+-----------+----------+----------+----------+-----------+----------+------------+
| id    | ts_code   | buydate  | buyprice | selldate | sellprice | duration | strategyid |
+-------+-----------+----------+----------+----------+-----------+----------+------------+
|  9985 | 000001.SZ | 20190404 | 13.86    | 20190408 | 14.43     |        1 | 2          |
|  9986 | 000006.SZ | 20190214 | 5.64     | 20190219 | 6.12      |        3 | 2          |

現在想把buyprice與sellprice,計算漲跌幅的運算:

 

 

mysql> select *,(a.sellprice-a.buyprice)*100/a.buyprice as gain from t_bt_strategy a where strategyid=2 and buyprice<sellprice;
+-------+-----------+----------+----------+----------+-----------+----------+------------+------------+
| id    | ts_code   | buydate  | buyprice | selldate | sellprice | duration | strategyid | gain       |
+-------+-----------+----------+----------+----------+-----------+----------+------------+------------+
|  9985 | 000001.SZ | 20190404 | 13.86    | 20190408 | 14.43     |        1 | 2          | 4.112554   |
|  9986 | 000006.SZ | 20190214 | 5.64     | 20190219 | 6.12      |        3 | 2          | 8.510638   |
|  9987 | 000011.SZ | 20190214 | 9.97     | 20190218 | 10.41     |        2 | 2          | 4.413240   |

 

OK。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章