顺序按子句中的多列-MySQL [英] Multiple column in order by clause - mysql
本文介绍了顺序按子句中的多列-MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在表中有两列,例如LIKE和FAVORITES(int值)
I have two columns in a table say, LIKE and FAVORITES (int value)
查看图表:
╔════╦══════╦══════════╗
║ ID ║ LIKE ║ FAVORITE ║
╠════╬══════╬══════════╣
║ 1 ║ 25 ║ 9 ║
║ 2 ║ 5 ║ 17 ║
║ 3 ║ 6 ║ 1 ║
║ 4 ║ 45 ║ 0 ║
║ 5 ║ 3 ║ 44 ║
╚════╩══════╩══════════╝
现在,我想从SELECT子句中选择最大喜欢"和收藏夹" ID. 我尝试过
Now, I want to select the Maximum Like and Favorites IDs from the SELECT clause. I have tried
SELECT ID from TABLE WHERE CONDITION ORDER BY LIKE,FAVORITES DESC
但是结果显示的是基于LIKE DESC顺序的行.
But the result shows the rows based on LIKE DESC order.
结果应该是
╔════╗
║ ID ║
╠════╣
║ 5 ║
║ 4 ║
║ 1 ║
║ 2 ║
║ 3 ║
╚════╝
推荐答案
我认为您需要添加这两列.例如,
I think you need to add those two columns. eg,
SELECT ID
FROM tableName
ORDER BY `LIKE` + FAVORITE DESC
- SQLFiddle演示
- SQLFiddle Demo
结果:
╔════╗
║ ID ║
╠════╣
║ 5 ║
║ 4 ║
║ 1 ║
║ 2 ║
║ 3 ║
╚════╝
这篇关于顺序按子句中的多列-MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文