Select
(Case when Grouping (Class) =1 then "total average" when Grouping (Student) =1 then "" Else class end) as Class
, (case where Grouping (Class) =1 then "when Grouping (Student) =1 then" average "else Student end) as Student
, AVG (Chinese) as language
, AVG (mathematics) as Mathematics
, AVG (English) as English
, AVG (total) as total score
From (
Select Class,student
, (select IsNull sum (Quantity), 0) from @tab where Class=t.class and Student=t.student and course= "language") as "language"
, (select IsNull (sum (Quantity), 0) from @tab where Class=t.class and Student=t.student and course= "mathematics") as "mathematics"
, (select IsNull sum (Quantity), 0) from @tab where Class=t.class and Student=t.student and course= "English") as "English"
, (select IsNull (sum (Quantity), 0) from @tab where Class=t.class and student=t.student) as "Total Score"
From @tab as T
GROUP BY Class,student
) as Temptab
GROUP by Class,student, Chinese, maths, English, total score with rollup
Having Grouping (Chinese) =1
and Grouping (mathematics) =1
and Grouping (English) =1
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.