我写了一个查询来计算产品的排名索引,查询在本地计算机上工作正常,但同样的查询在实时服务器中不起作用。
本地:Mysql 5.5.38 直播:Mysql 5.6.20
select
x . *
from
(select
productID,
productname,
price,
mobile_score,
format((((5 / 100) * mobile_score) + (5 - (@ctrnk:=@ctrnk + 1) * (5 / (select
count(*)
from
product a
CROSS JOIN (SELECT @ctrnk:=- 1) c
join product b ON a.productID = b.productID
where
a.mobile_score = 82 and a.categoryID != 13 and a.price > 0
order by a.price asc)))) / 2, 2) as indexscore
from
product
where
mobile_score = 82 and categoryID != 13 and price > 0
order by price asc) as x
where productID = 1923
Local :
productID productname price mobile_score indexscore
1923 Xiaomi MI3 13999 82 4.55
Live :
productID productname price mobile_score indexscore
1923 Xiaomi MI3 13999 82 Null