2011-06-11 68 views
0

我有以下表SQL - 從表格數據創建彙總統計

Manager-category StartDate Enddate 
A     1/1/2002  2/2/2007 
B     1/5/2005  4/5/2005 
etc.... 

我需要創建彙總統計如下圖所示(摘要)

Year CountofCategoryA who started CountofCategoryB who started 
2003 
etc 

我可以進行更新生成上表對於每個單元格,在Access I中使用

UPDATE summary, 
     (A query that gives a count in a year) as counttab 
    SET summary.column = counttab.count 
WHERE summary.Year = currentyear 

我必須爲每個單元格運行此查詢是否存在更快/更高效的方式?

+0

細胞? Access沒有「單元格」 - 這是一個電子表格的事情。 – 2011-06-12 21:44:23

回答

0

這聽起來像你正在尋找一個交叉表查詢:

TRANSFORM Count(*) AS Expr2 
SELECT Year([StartDate]) AS Expr1 
FROM SomeTable 
GROUP BY Year([StartDate]) 
PIVOT SomeTable.[Manager-category];