我正在MySQL中进行查询,结果不按百分比排序。我怎样才能按百分比强制订货?它是按total_sold排序的,而不是按百分比排序的。
以下是代码:
SELECT in_disassembly.car_id,
in_disassembly.cost,
IFNULL(SUM(product_sold.product_total_price),0) AS total_sold,
concat((IFNULL(SUM(product_sold.product_total_price),0)
/in_disassembly.cost * 100)) AS percentage_sold
FROM in_disassembly
INNER JOIN product_sold ON product_sold.product_car_id = in_disassembly.car_id
WHERE in_disassembly.car_id > $start_id AND in_disassembly.car_id < $end_id
GROUP BY in_disassembly.car_id
ORDER BY percentage_sold固定码
SELECT in_disassembly.car_id, in_disassembly.cost, IFNULL(SUM(product_sold.product_total_price),0) AS total_sold, ROUND((IFNULL(SUM(product_sold.product_total_price),0)/in_disassembly.cost * 100),0) AS percentage_sold
FROM in_disassembly
INNER JOIN product_sold ON product_sold.product_car_id = in_disassembly.car_id
WHERE in_disassembly.car_id > $start_id AND in_disassembly.car_id < $end_id GROUP BY in_disassembly.car_id ORDER BY percentage_sold DESC发布于 2013-12-25 22:56:32
你在那里用CONCAT做一个字符串,所以它将被排序为string。也就是说,1之后是11,然后是2。
发布于 2013-12-25 22:55:44
您在percentage_sold订购后丢失了ASC或DESC。
发布于 2013-12-25 23:00:03
尝试不将百分比连接到字符串,它应该可以工作。
https://stackoverflow.com/questions/20777429
复制相似问题