0

How can I group pivot query by the category. I can achieve this in Excel but I wanted to do in SQL Oracle query.

Let say we have data like this:-

enter image description here

I can simply pivot to get grade count by subject

select * from (select studentID, subject, grade from table_student)
PIVOT 
(
sum (grade) FOR (subject) IN ('A','B','C')
)
order by studentID;

and get grade count by category

select * from (select studentID, category, grade from table_student)
PIVOT 
(
sum (grade) FOR (category) IN ('Common','Science')
)
order by studentID;

But my question can I combine these query and get result like below using SQL?

combine category and subject

Thank you!!

1
  • Please provide you data as text and not as a picture. How should one load a picture in a database to test the query?
    – miracle173
    Mar 10 at 8:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.