Access 2007 Crosstab Query Expression

二次信任 提交于 2019-12-01 10:26:36

问题


Goal: to create a percentage column based off the values of calculated columns.

Here's the SQL code of the Crosstab query:

TRANSFORM Count(Master_Calendar.ID) AS CountOfID
SELECT Master_Calendar.Analyst, Count(Master_Calendar.ID) AS [Total Of ID]
FROM Master_Calendar
GROUP BY Master_Calendar.Analyst
PIVOT Master_Calendar.[Current Status];

This gives me a crosstab query that displays the amount of entries in the database that are "Completed", "In Process", or "Not Started", sorted by which Analyst they belong to.

What I'm trying to do is add another column to calculate the Percent Complete -- so (Completed / Total of ID) * 100. I tried putting that into an expression in another cell, but it returns with a "[Completed]" not found, even though it gives me it as an option in the Expression Builder.

Am I just naming my variables wrong, or is it not possible to do it this way? Can I reference the total count of the records that contain "Completed" using query code instead of finding out the value using a Pivot table?

Thanks for your help.


回答1:


Try:

SELECT 
    xTab.Analyst,
    [Completed]/([Total of ID]/100) AS [Complete%], 
    [In Process]/([Total of ID]/100) AS [In Process%],
    [Not Started]/([Total of ID]/100) AS [Not Started%]
FROM xTab;


来源:https://stackoverflow.com/questions/11123168/access-2007-crosstab-query-expression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!