我在查询如何在select块中添加if else时遇到问题我也想要一些更好的方法来编写以下查询
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)
});
答案 0 :(得分:2)
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);
您发布的问题:
我想确定投注(投注)比客户在投注历史中的平均投注高10倍以上的投注...
您的数据,其中Id =客户ID。请注意,没有平均投注* 10高于投注的情况,因此根据您在问题中定义的内容,您的样本数据中没有异常投注。
Id:1,AverageBet:400,AverageBetTimes10:4000,最高赌注:1000
Id:2,AverageBet:15,AverageBetTimes10:150,最高赌注:20
Id:3,AverageBet:110,AverageBetTimes10:1100,最高赌注:300
Id:4,AverageBet:237.5,AverageBetTimes10:2375,最高赌注:300
Id:5,AverageBet:73.3333333333333,AverageBetTimes10:733.333333333333,最高赌注:100
Id:6,AverageBet:162.5,AverageBetTimes10:1625,最高赌注:500