通过排序数据获取不同的值 [英] get Distinct Values with Sorted Data
本文介绍了通过排序数据获取不同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个查询来获取不同的键,这些键根据Mongodb 1.6.5
I need a Query to get distinct keys with sorted on basis of score in Mongodb 1.6.5
我有类似
{key ="SAGAR"
score =16
note ="test1"
}
{key ="VARPE"
score =17
note ="test1"
}
{key ="SAGAR"
score =16
note ="test2"
}
{key ="VARPE"
score =17
note ="test2"
}
我需要一个查询,该查询按分数对所有记录进行排序并为我返回不同的键.....
I need a query which sorts all records on score and returns me distinct key.....
推荐答案
您可以这样使用与众不同的内容:
you can use distinct like this:
db.test.distinct({"key":true,"score":true,"note":true});
在关系数据库中相同:
SELECT DISTINCT key,score,note FROM test;
通过添加以下代码,排序结果 /p>
And than sort result by adding following code:
.sort({score : 1}) // 1 = asc, -1 = desc
总结果将如下所示:
db.test.distinct({"key":true,"score":true,"note":true}).sort({score : 1});
这篇关于通过排序数据获取不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文