它对应的SQL语句如下: TRANSFORM Sum(Table3.Score) AS ScoreOfSum SELECT Table3.sName, Table3.sClass, Sum(Table3.Score) AS [Total Of Score] FROM Table3 GROUP BY Table3.sName, Table3.sClass PIVOT Table3.Course;
3. 把这个查询代入到一开的那个交叉查询中,替代原来的table3. 把把所有的table3. 换成 t. 如下
TRANSFORM Sum(t.Score) AS ScoreOfSum SELECT t.sName, t.sClass, Sum(t.Score) AS [Total Of Score] FROM Table3 GROUP BY t.sName, t.sClass PIVOT t.Course;
然后再把 from table3 变成
TRANSFORM Sum(t.Score) AS ScoreOfSum SELECT t.sName, t.sClass, Sum(t.Score) AS [Total Of Score] FROM (select sName,sClass,Course,Score from Table3 union all select 'Total' as sName,null as sClass,course,avg(score) from table3 group by course) t GROUP BY t.sName, t.sClass PIVOT t.Course;
select 'subtotal' as sName,sClass,course,avg(score) from table3 group by course,sClass 这样改为 TRANSFORM Sum(t.Score) AS ScoreOfSum SELECT t.sName, t.sClass, Sum(t.Score) AS [Total Of Score] FROM (select sName,sClass,Course,Score from Table3 union all select 'subtotal' as sName,sClass,course,avg(score) from table3 group by course,sClass union all select 'Total' as sName,null as sClass,course,avg(score) from table3 group by course ) t GROUP BY t.sName, t.sClass,(t.sClass='subtotal'),(t.sClass='Total') order by (t.sClass='Total') desc,(t.sClass='subtotal') desc,sClass PIVOT t.Course