gpt4 book ai didi

linq - 在 linq 查询中有条件 count()

转载 作者:行者123 更新时间:2023-12-04 14:36:58 26 4
gpt4 key购买 nike

我想创建这个查询:

select Something, count(Something) as "Num_Of_Times"
from tbl_results
group by Something
having count(Something)>5

我从这个开始:
tempResults.GroupBy(dataRow => dataRow.Field<string>("Something"))
.Count() //(.......what comes here , to make Count()>5?)

最佳答案

from item in tbl_results
group item by item.Something into groupedItems
let count = groupedItems.Count()
where count > 5
select new { Something = groupedItems.Key, Num_Of_Times = count };

更新:这会给你的结果为 IQueryable<DataRow> :
DataTable dt= new DataTable();
dt.Columns.Add("Something", typeof(int));
dt.Columns.Add("Num_Of_Times", typeof(int));

var results = (from item in tbl_results
group item by item.Something into groupedItems
let count = groupedItems.Count()
where count > 2
select dt.Rows.Add(groupedItems.Key, count)).AsQueryable();

(请注意,它还填充了 dt 表)

关于linq - 在 linq 查询中有条件 count(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1333265/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com