使用linq找到第二个牧师号码 [英] find the 2nd hiest number using linq
本文介绍了使用linq找到第二个牧师号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
id name mid
===========
1 A null
2 B 1
3 C null
4 D 1
在上表中,我想编写查询以使用linque获取第二高的id
怎么能我这样做
In the above table i want to write the query to fetch the second highest id using linque
How can i do that
推荐答案
http:// www。 functionx.com/csharp/linq/Lesson03.htm [ ^ ]
您可能需要先做一个区别:
http://www.functionx.com/csharp/linq/Lesson03.htm[^]
You might have to do a Distinct first:
var c = (from x in olist order by mid descending select mid).Distinct().Skip(1).First();
像这样:
Like this:
int secondHighest = (from Id in MyTable
orderby Id descending
select Id).Skip(1).First();
了解更多关于MSDN上的Skip:
http://msdn.microsoft.com/en-us/library/bb358985.aspx [ ^ ]
这篇关于使用linq找到第二个牧师号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文