对于我的产品的客户评论,我将它们存储在SQL中,如下所示:
durability | cost | appearance
----------------------------------
5 | 3 | 4
2 | 4 | 2
1 | 5 | 5
每个值在三个类别中是五分之一。
当我想在页面上打印此信息时,我想按个别评论的平均分数降序排列。
SELECT *
FROM reviews
ORDER BY (durability+cost+appearance)/3 DESC
显然这不起作用,但是有办法得到我的结果吗?我不想在SQL中包含average
列,因为在这个小应用程序之外,它没有任何用途。
答案 0 :(得分:2)
使用ORDER BY
代替SORT BY
:
SELECT *
FROM reviews
ORDER BY (durability+cost+appearance)/3 DESC
修改强>
要按值查看订单,请尝试在select子句中再添加一列:
SELECT *,(durability+cost+appearance)/3 as OrderValue
FROM reviews
ORDER BY (durability+cost+appearance)/3 DESC
示例输出:
DURABILITY COST APPEARANCE ORDERVALUE
5 3 4 4
1 5 5 3
2 4 2 2