我想返回一个简单计算的结果,但我不确定如何做到这一点。我的表格如下:
SELECT
COUNT(fb.engineer_id) AS `total_feedback`,
SUM(fb.rating) AS `total_rating`, fb.engineer_id
FROM
`feedback` AS fb
现在当我返回结果时,我使用PHP来进行计算,但现在我想通过结果对结果进行排序(此查询嵌套在一个更大的结果中)。
计算如下:
$p = ((($total_rating*20)*$total_feedback)/10);
这可以在初始查询中完成吗?
答案 0 :(得分:2)
你可以做到
SELECT
COUNT(fb.engineer_id) AS `total_feedback`,
SUM(fb.rating) AS `total_rating`, fb.engineer_id
FROM
`feedback` AS fb
ORDER BY total_rating*20*total_feedback/10
或者如果您想在结果中使用该列:
SELECT
COUNT(fb.engineer_id) AS `total_feedback`,
SUM(fb.rating) AS `total_rating`, fb.engineer_id
total_rating*20*total_feedback/10 AS p
FROM
`feedback` AS fb
ORDER BY p
答案 1 :(得分:0)
您的查询没有groub by
子句,因此只返回一行,那么您想如何订购结果?