你打开透视表,在数据源,连接属性,定义,命令文本里,有SELECT语句,如下:
select (select count(成绩1) as 数量 from (select 科目,姓名,sum(成绩) as 成绩1 from (select * from (select "语文" as 科目,姓名,语文 as 成绩 from [成绩$] union all select "数学" as 科目,姓名,数学 as 成绩 from [成绩$] union all select "英语" as 科目,姓名,英语 as 成绩 from [成绩$] ) where 科目="语文") group by 科目,姓名) A1 where A1.成绩1 >=A2.成绩1) as 名次,A2.科目,A2.姓名,A2.成绩1 from (select 科目,姓名,sum(成绩) as 成绩1 from (select * from (select "语文" as 科目,姓名,语文 as 成绩 from [成绩$] union all select "数学" as 科目,姓名,数学 as 成绩 from [成绩$] union all select "英语" as 科目,姓名,英语 as 成绩 from [成绩$] ) where 科目="语文") group by 科目,姓名 ) A2 union all
select (select count(成绩1) as 数量 from (select 科目,姓名,sum(成绩) as 成绩1 from (select * from (select "语文" as 科目,姓名,语文 as 成绩 from [成绩$] union all select "数学" as 科目,姓名,数学 as 成绩 from [成绩$] union all select "英语" as 科目,姓名,英语 as 成绩 from [成绩$] ) where 科目="数学") group by 科目,姓名) A1 where A1.成绩1 >=A2.成绩1) as 名次,A2.科目,A2.姓名,A2.成绩1 from (select 科目,姓名,sum(成绩) as 成绩1 from (select * from (select "语文" as 科目,姓名,语文 as 成绩 from [成绩$] union all select "数学" as 科目,姓名,数学 as 成绩 from [成绩$] union all select "英语" as 科目,姓名,英语 as 成绩 from [成绩$] ) where 科目="数学") group by 科目,姓名 ) A2 union all
select (select count(成绩1) as 数量 from (select 科目,姓名,sum(成绩) as 成绩1 from (select * from (select "语文" as 科目,姓名,语文 as 成绩 from [成绩$] union all select "数学" as 科目,姓名,数学 as 成绩 from [成绩$] union all select "英语" as 科目,姓名,英语 as 成绩 from [成绩$] ) where 科目="英语") group by 科目,姓名) A1 where A1.成绩1 >=A2.成绩1) as 名次,A2.科目,A2.姓名,A2.成绩1 from (select 科目,姓名,sum(成绩) as 成绩1 from (select * from (select "语文" as 科目,姓名,语文 as 成绩 from [成绩$] union all select "数学" as 科目,姓名,数学 as 成绩 from [成绩$] union all select "英语" as 科目,姓名,英语 as 成绩 from [成绩$] ) where 科目="英语") group by 科目,姓名 ) A2 |