按两个字段的和 [英] Order By Sum of Two Fields

查看:141
本文介绍了按两个字段的和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个包含karma_up和karma_down的表。每次有人投票karma_up得到增加,每次有人投票karma_down也增加一。我如何拉这些选择的行,并让他们排序的这些新的值的总和? ORDER BY(karma_up - karma_down)似乎不工作,我想要什么。

Let's say I have a table with karma_up and karma_down. Everytime someone votes up karma_up gets incremented and everytime someone votes down karma_down gets incremented one as well. How can I pull these a selection of rows and have them ordered by the sum of these new values? ORDER BY (karma_up - karma_down) does not seem to work how I want. I simply want the rows with the highest karma up top.

推荐答案

非常简单

SELECT 
ID, KARMA_UP, KARMA_DOWN, (KARMA_UP-KARMA_DOWN) AS USER_KARMA 
FROM KARMA 
ORDER BY USER_KARMA DESC

这篇关于按两个字段的和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆