1

我正在整理一个交叉表,我想要一个按月分组的多列值(所有数字)的报告。这是我使用的 SQL。我知道这不会带来预期的结果。每个“timex”列都有不同的数字。我想要一个返回按月分组的列的总和的查询。

TRANSFORM Sum(tblTimeTracking.time1+ tblTimeTracking.time2+ tblTimeTracking.time3+ tblTimeTracking.time4+ tblTimeTracking.time5+ tblTimeTracking.time6+ tblTimeTracking.time7+ tblTimeTracking.time8+ tblTimeTracking.time9+ tblTimeTracking.time10+ tblTimeTracking.time11+ tblTimeTracking.time12+ tblTimeTracking.time13+ tblTimeTracking.time14+ tblTimeTracking.time15+ tblTimeTracking.time16+ tblTimeTracking.time17+ tblTimeTracking.time18+ tblTimeTracking.time19+ tblTimeTracking.time20+ tblTimeTracking.time21+ tblTimeTracking.time22 ) AS Total SELECT tbl_vlookup.Manager AS Manager FROM tbl_vlookup INNER JOIN tblTimeTracking ON tbl_vlookup.[Associate Name] = tblTimeTracking.Associate GROUP BY tbl_vlookup.Manager PIVOT Format([Day],"yyyy-mm");

Associate    Day          Time 1    Time 2  Time 3  Time 4  Time 5  Time 6  Time 7   
John Smith  12/1/9999       1         0       0      5.5      1      0.25   0.25
4

1 回答 1

1

像这样的东西:

TRANSFORM Sum(q.Time1) AS SumOfTime1
SELECT q.Associate, q.Day
FROM (SELECT t.Associate, t.Day, t.Time1,"Time1" As TimeType
FROM tbl t
UNION ALL
SELECT t.Associate, t.Day, t.Time2,"Time2" As TimeType
FROM tbl t
UNION ALL
SELECT t.Associate, t.Day, t.Time3,"Time3" As TimeType
FROM tbl t)  AS q
GROUP BY q.Associate, q.Day
PIVOT q.TimeType;

正如我所提到的,你需要把桌子弄平。它似乎只是不同类型的数据:)

于 2013-01-10T16:34:54.403 回答