public ActionResult List_of_Winners(int id=0)
{
var winners = (from cat in db.Events_Category_tbl
join can in db.Candidates_Info_tbl
on cat.events_category_id equals can.events_category_id
where cat.events_info_id == id
select new Candidates
{
events_category_name = cat.events_category_name,
candidates_fullname = can.candidates_fullname,
candidates_info_id = can.candidates_info_id,
events_category_id = cat.events_category_id,
no_of_votes = can.no_of_votes.Value
}).OrderBy(x => x.no_of_votes).Distinct();
return PartialView(winners);
}
我有2个表,Events_Category_tbl & Candidates_Info_tbl
然后在一个类别中有许多候选人注册。然后,我想要做的是我只需要获得该类别中的最高票数。而这也是该类别的赢家。
我的候选人表格如下:
candidates_info_id,
candidates_fullname,
events_category_id,
no_of_votes
我的分类表看起来像这样:
events_category_id,
events_category_name
然后,我想在我的查询中得到一个结果,在一个类别中,它有一个候选人获得最高票数。
我该怎么做? 以上是我的代码。