2

I am designing a form to show employees' salary information. I need the form to show salary for years 2007 - 2013 in addition to their other personal info.

The form should look like this:

 Name   Department   Sub Department

        2007 2008 2009 2010 2011 2012 2013
 Salary  x
 Bonus   y
 Total  x+y

 Various stats:  
 Calls Stats 2013      [a]  [c]
 Marketing Stats 2013  [b]  [d]
 Sales Rank 2011       [x]
 Sales Rank 2012       [y]
 Sales Rank 2013       [z]

I have tried everything to get the years to work properly but to no avail. I have tried making one large query. I have tried making multiple queries and plugging them in.

My tables are:

  • EmpTable
  • CompensationTable
  • DepartmentTable
  • StatsTable

CompTable and StatsTable have a year column so each year has different salary/stats.

What are the steps to setting up a form like this? I have tried several things but none of them are working. I want it all to be on one page so I don't want to use split form unless I really have to.

EDIT: Schema:

   EmpTable       CompTable        DeptTable                StatsTable
                  PK CompID                                PK StatsID
   PK ID   ------>FK ID   -----> PK/FK ID (From emp) ----> FK ID (From emp)
      Name           Year           Dept                      Year 
      Etc.           Salary                                   Rank

Solutions I have tried:

  1. Making one large query with no normalization. For example it has columns for each year. Used to work but doesn't work now because I fixed normalization in my tables.
  2. Making one large query with multiple queries. Each individual query for each year. For example, 2013 Comp Query + 2012 Comp Query all into one big query. Doesn't work because too many fields. (more than 127)
4

1 回答 1

0

您正在寻找的是交叉表查询。

http://allenbrowne.com/ser-67.html 是一个很好的起点。

如果您使用 Access 查询生成器,您可以轻松生成所需的查询。这与在 Excel 中制作数据透视表的体验类似。

您必须选择:

Column Heading年数如下Crosstab

雇员Row Heading如下Crosstab

工资Value如下Crosstab

工资Sum如下Total

大致看起来像这样

TRANSFORM Sum(CompensationTable.Salary) AS SumOfSalary
SELECT EmpTable.EmpName
FROM ((EmpTable INNER JOIN StatsTable ON EmpTable.ID = StatsTable.ID) INNER JOIN DepartmentTable ON EmpTable.ID = DepartmentTable.ID) INNER JOIN CompensationTable ON EmpTable.ID = CompensationTable.ID
GROUP BY EmpTable.EmpName
PIVOT StatsTable.Yr;
于 2013-06-19T14:38:43.577 回答