我从此表中提取SQL Server中的一些数据。
ID_Number Date_01 Date_02 Date_03 Date_04 Date_05
---------------------------------------------------------------------
1001 6/1/2015 6/5/2015 Null Null 6/6/2015
1001 Null Null 6/5/2015 Null 6/7/2015
1002 6/20/2015 Null Null 6/21/2015 Null
1002 6/21/2015 6/22/2015 6/23/2015 6/19/2015 6/20/2015
1003 6/25/2015 Null Null 6/26/2015 6/29/2015
我不确定我将使用哪个CTE查询来为每个ID返回一行,并获得每个ID的每列最大日期。
以下是样本结果:
ID_Number Date_01 Date_02 Date_03 Date_04 Date_05
----------------------------------------------------------------------
1001 6/1/2015 6/5/2015 6/5/2015 Null 6/7/2015
1002 6/21/2015 6/22/2015 6/23/2015 6/21/2015 6/20/2015
1003 6/25/2015 Null Null 6/26/2015 6/29/2015
答案 0 :(得分:2)
您不需要Dim mySum As Int32 = something.Sum(Function(item) item.Amount)
来执行此操作,如果没有错误,简单CTE
Group by
聚合应该适合您
Max
答案 1 :(得分:0)
每个ID的每列最大日期
按ID_Number分组:
SELECT ID_Number AS Expr1, MAX(Date_01) AS Date_01, MAX(Date_02) AS Date_02, MAX(Date_03) AS Date_03, MAX(Date_04) AS Date_04, MAX(Date_05) AS Date_05
FROM ta1
GROUP BY ID_Number