我是excel公式和宏的新手。我的表格如下所示。
id Date name hours code workPackage
1 3/28/2012 Anit 8 N1 1212
2 3/29/2012 Anit 8 N2 1212
3 3/30/2012 Anit 8 N2 1214
4 3/31/2012 Anit 8 N4 1212
5 4/1/2012 Anit 5 N1 1212
6 4/1/2012 Anit 3 N2 1212
7 4/3/2012 Anit 8 N2 1222
8 4/4/2012 Anit 8 N2 1212
9 4/5/2012 Anit 8 A1 1212
10 4/6/2012 Anit 8 A1 1212
我希望根据Code和workPackage将这些每日数据累积到每周(周五)。对于特定代码和工作包,添加该周的小时数。最终的输出数据应该是这样的。
1 3/30/2012 Anit 8 N1 1212
2 3/30/2012 Anit 8 N2 1212
3 3/30/2012 Anit 8 N2 1214
4 4/6/2012 Anit 16 A1 1212
5 4/6/2012 Anit 5 N1 1212
6 4/6/2012 Anit 19 N2 1212
7 4/6/2012 Anit 8 N4 1212
如果可以通过在访问数据库或任何其他数据库中导入此数据来编写查询,那么它也会很棒。
答案 0 :(得分:2)
您可以在Excel中使用ADO。查询将是:
Select Code, WorkPackage, Max([date]), First([Name]), Sum([Hours])
From [Sheet1$]
Group By Code, WorkPackage
参考:http://support.microsoft.com/kb/257819
编辑重新评论
SELECT t.code, t.workPackage, Format([Date],"yyyy-ww") AS WeekNo,
Min(t.Date) AS MinOfDate, Max(t.Date) AS MaxOfDate,
Min(t.name) AS MinOfname, Sum(t.hours) AS SumOfhours
FROM [Sheet1$] t
GROUP BY t.code, t.workPackage, Format([Date],"yyyy-ww");