MS Access Rank GPA With Grouping

时间:2014-01-09 22:28:48

标签: sql ms-access group-by rank

我已经接近找到一个分组排名的答案但不完全。我有2张桌子

组织表

Chapter Council
DDD     IFC
DT      IFC
GG      IFC
AA      MGC
BB      MGC
CC      MGC
DD      IND
EE      IND

PSRoster

Chapter GRDPoints  TakeGPA  MemberName  Status
DDD    2.0           2         Bill     Active
DT     3.2           3         Jim      New Member
GG     4.0           6         Sue      New Member
AA     2.3           6         Jill     Active
BB     1.3           5         Joe      New Member
CC     3.2           5         Frank    Active
DD     3.2           4         Leslie   Active
EE     4.0           3         Sandra   Active

我必须动态计算每个章节的GPA,然后对它们进行排名并按理事会对它们进行分组。我没有问题计算GPA然后进行子查询以获得其他值,但我似乎无法使排名工作。下面是我的SQL。我缺少什么才能让理事会对GPA进行排名?

SELECT 
    Org.Council, 
    Org.Chapter, 
    Round((Sum(PSRoster.GrdPoints)/Sum(PSRoster.TakeGPA)),3) AS [Chapter Average],
    ( 
        Select Round((Sum(PSRoster.GrdPoints)/Sum(PSRoster.TakeGPA)),3) AS [Chapter Average] 
        FROM Org INNER JOIN PSRoster ON Org.Chapter = PSRoster.Chapter 
        WHERE PSRoster.Status = 'Active'  
    ) AS [Active Avg GPA],
    ( 
        Select Round((Sum(PSRoster.GrdPoints)/Sum(PSRoster.TakeGPA)),3) AS [Chapter Average] 
        FROM Org 
        INNER JOIN PSRoster ON Org.Chapter = PSRoster.Chapter 
        WHERE PSRoster.Status = 'New Member'  
    ) AS [New Member Avg GPA],
    (
        SELECT COUNT(PSRoster.Semester) AS [Total Number of 4] 
        FROM PSRoster 
        WHERE (PSRoster.Semester = 4.00  ) And Org.Chapter = PSRoster.Chapter 
    ) AS [FourOs]
FROM Org INNER JOIN PSRoster ON Org.Chapter = PSRoster.Chapter
Group By Org.Council, Org.Chapter;

0 个答案:

没有答案