没有公式的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。