[英]Linq calculate average,total and compare the result in query
I am having trouble in following query that how to add if else in select block also I want some better way to write the following query 我在以下查询中遇到麻烦,即如何在选择块中添加其他内容,我也想要一些更好的方法来编写以下查询
var x = csvParser.ParseCsv(@"data.csv");
var unsettledCustomers = x.GroupBy(g=>g.Id).
Select(gg =>new
{
Id=g.Key,
Total=g.Sum(xx=>xx.Stake),
Avg=g.Average(ss=>ss.Win)
});
var unsettledCustomers = x.GroupBy(g => g.Id)
.Select(g => new
{
Id = g.Key,
Total = g.Sum(xx => xx.Stake),
Avg = g.Average(ss => ss.Win),
AvgerageBet = g.Average(ss => ss.Stake),
UnusualBets = g.Where(bet => bet.Stake > (10 * g.Average(ss => ss.Stake))).ToList()
});
var allUnusualBets = unsettledCustomers.SelectMany(y => y.UnusualBets);
Your posted question: 您发布的问题:
I want to identify Bets where the stake (bet) is more than 10 times higher than that customer's average bet in their betting history...
我想确定赌注(下注)比其投注历史中该客户的平均下注高出10倍以上的赌注...
Your data where Id = the customer id. 您的数据,其中ID =客户ID。 Note that there are no instances where the average bet * 10 is higher than the bet placed so there are no unusual bets in your sample data according to what you have defined in your question.
请注意,在任何情况下,平均下注* 10都不比下注高,因此根据您在问题中定义的内容,样本数据中也没有异常下注。
Id: 1, AverageBet: 400, AverageBetTimes10: 4000, Highest bet: 1000
Id:1,平均投注:400,平均投注时间10:4000,最高投注:1000
Id: 2, AverageBet: 15, AverageBetTimes10: 150, Highest bet: 20
Id:2,平均投注:15,平均投注时间10:150,最高投注:20
Id: 3, AverageBet: 110, AverageBetTimes10: 1100, Highest bet: 300
Id:3,平均投注:110,平均投注时间10:1100,最高投注:300
Id: 4, AverageBet: 237.5, AverageBetTimes10: 2375, Highest bet: 300
Id:4,平均投注:237.5,平均投注时间10:2375,最高投注:300
Id: 5, AverageBet: 73.3333333333333, AverageBetTimes10: 733.333333333333, Highest bet: 100
Id:5,平均投注:73.3333333333333,平均投注时间10:733.333333333333,最高投注:100
Id: 6, AverageBet: 162.5, AverageBetTimes10: 1625, Highest bet: 500
Id:6,平均投注:162.5,平均投注时间10:1625,最高投注:500
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.