mysql order by 报错_Mysql 使用 select as 的值 order by 出现数据错误问题

使用 inner join 查询,如果使用 percent1 排序就会出现结果里面的 percent1 值是错误的,先看不排序的sql。

select `stock`.*, `stock1`.`price_current` as `price_current1`, `stock1`.`rank` as `rank1`, `stock`.`price_current` - `stock1`.`price_current` as `percent1` from `stock` inner join `stock` as `stock1` on `stock`.`code` = `stock1`.`code` and `stock`.`date` = '2016-10-10' and `stock1`.`date` = '2016-09-30' and `stock`.`code` = '600817'\G

结果

id: 174

code: 600817

name: *ST 宏盛

price_yesterday: 18.55

price_today: 18.61

price_current: 18.53

percent: -0.11

highest: 18.67

lowest: 18.35

swing: 1.73

high_limit: 19.48

low_limit: 17.62

value_total: 29.82

value_trade: 28.85

date: 2016-10-10

rank: 9

created_at: 2016-10-10 09:10:08

updated_at: 2016-10-10 14:57:08

price_current1: 18.55

rank1: 9

percent1: -0.02

此时percent1是-0.02,我们加上order by percent1再看

select `stock`.*, `stock1`.`price_current` as `price_current1`, `stock1`.`rank` as `rank1`, `stock`.`price_current` - `stock1`.`price_current` as `percent1` from `stock` inner join `stock` as `stock1` on `stock`.`code` = `stock1`.`code` and `stock`.`date` = '2016-10-10' and `stock1`.`date` = '2016-09-30' and `stock`.`code` = '600817' order by `percent1` desc\G

结果

id: 174

code: 600817

name: *ST 宏盛

price_yesterday: 18.55

price_today: 18.61

price_current: 18.53

percent: -0.11

highest: 18.67

lowest: 18.35

swing: 1.73

high_limit: 19.48

low_limit: 17.62

value_total: 29.82

value_trade: 28.85

date: 2016-10-10

rank: 9

created_at: 2016-10-10 09:10:08

updated_at: 2016-10-10 14:57:08

price_current1: 18.55

rank1: 9

percent1: 0.00

可以看到最后的 percent1 竟然变成 0.00 了,查了一上午都没找到原因,求指导

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值