from X in XXX
where 條件
group X by new { 要群組的欄位 } into g
from Xx in g.DefaultIfEmpty()
orderby {要遞增排序的欄位}
select new
{
X.zzz,
Xx.xxx(經過群組的欄位),
DateType = X.xx == "A" ? "1~30" :
X.xx == "B" ? "31~60" :""(Case when)
}
#region 用Count()得出查詢結果的個數
var langCount = (from s in GetStudents()
select s.Language)
.Distinct()
.Count();
var ageCoun = (from s in GetStudents()
select s.Age)
.Count(a=>a>22);
#endregion
#region 用Sum()將查詢結果相加
var ageSum = (from s in GetStudents()
select s.Age)
.Sum();
//var ageSum = GetStudents().Sum(s=>s.Age);
#endregion
#region 用Min()得出查詢結果的最小值
var ageMin = (from s in GetStudents()
select s.Age)
.Min();
//var ageMin = GetStudents().Min(s => s.Age);
#endregion
#region 用Max()得出查詢結果的最大值
var ageMax = (from s in GetStudents()
select s.Age)
.Max();
//var ageMax = GetStudents().Max(s => s.Age);
#endregion
#region 用Average()得出查詢結果的平均值
var ageAverage = (from s in GetStudents()
select s.Age)
.Average();
//var ageAverage = GetStudents().Average(s => s.Age);
#endregion
沒有留言:
張貼留言