troubleshooting Question

How to display row value of each class as a column value

Avatar of jyothsna1803
jyothsna1803 asked on
Oracle DatabaseSQL
8 Comments1 Solution447 ViewsLast Modified:
How to display row value of each class as a column value

ID      NAME      CLASS            HOURS      SCHOOLNAME
1      Allen      Maths            12      school1
2      Sam      Maths            12      school1
4      Pam      Maths            10      school1
3      Sam      Comp            10      school1
9      Smith      Comp            15      school1
7      Smith      Phy            20      school1
5      Pam      Phy            12      school1
6      Pam      Accounts      15      school1
8      Smith      Accounts      12      school1
10      Adams      Business      30      school1
11      Anthony      Comp            20      school2
12      Chris      Business      20      school2
13      Chris      Accounts      20      school2
14      Angelo      Maths            20      school3
15      Angelo      Accounts      15      school3
16      Robert      Accounts      15      school3
17      Robert      Maths            15      school3

                  




I wanted output like below for School1

Name      maths      Comp      Phy      Accounts      Business
Allen      12      0      0      0            0
Sam      12      10      0      0            0
Pam      10      0      12      15            0
Smith      0      15      20      12            0
Adams      0      0      0      0            30


I wanted output like below for School2

Name            Comp      Accounts      Business
Anthony            20      0            0
Chris            10      20            20


I wanted output like below for School3

Name      maths      Accounts
Angelo      20      15
Robert      15      15
how to wriite a single query, Also i may add /delete school/class anytime. Query should support mesans everything dynamically should get the data.
Thanx in advance
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros