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。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值