본문 바로가기
C# /LINQ

람다식 UNION ALL 과 UNION 구현 방법

by Hwoarang757 2015. 6. 26.

 

UNION ALL // 중복된 항목 병합

 

List<DataResult>.GroupBy(n => n.ColName).

                                        Select(j => new { ColName = j.Key , avg = Math.Round(decimal.Parse(j.Average(g => g.Value.HasValue ? g.Value : 0).ToString())) })

                           

.Concat(List<DataResult>.GroupBy(n => n.ColName).

                                        Select(j => new { ColName = j.Key , avg = Math.Round(decimal.Parse(j.Average(g => g.Value.HasValue ? g.Value : 0).ToString())) }));

 

 

 

 

 

UNION // 중복된 항목 제거

 

List<DataResult>.GroupBy(n => n.ColName).

                                        Select(j => new { ColName = j.Key , avg = Math.Round(decimal.Parse(j.Average(g => g.Value.HasValue ? g.Value : 0).ToString())) })

                           

.Union(List<DataResult>.GroupBy(n => n.ColName).

                                        Select(j => new { ColName = j.Key , avg = Math.Round(decimal.Parse(j.Average(g => g.Value.HasValue ? g.Value : 0).ToString())) }));