Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Building a Dynamic Matrix Query

770334Apr 30 2010 — edited Apr 30 2010
I am new to both Oracle and to the forums so any assistance or direction you can provide would be GREATLY appreciated. Below I've outlined the table structure that I'm working with, and then below that I've outlined exactly what I'm trying to accomplish.
-----
Table: PRODUCTS
Description: Stores all of the company's products
Columns: product_id (pk), product_name
Records:
1 - Voice
2 - Internet
3 - Cable
4 - Other

Table: TESTS
Description: Stores the test cases for our environment. Each test has a status_id that is the foreign key from the STATUSES table below.
Columns: test_id (pk), test_name, status_id (fk)
Records:
1 - Test one - 1
2 - Test two - 1
3 - Test Three - 3
4 - Test Four - 2

Table: PRODUCTSTESTSMAPPING
Description: Stores the test to product mapping information. Tests can be linked to multiple products.
Columns: product_id (fk), test_id (fk)
Records:
1 - 1
1 - 3
2 - 1
2 - 2
2 - 3
2 - 4
3 - 1

Table: STATUSES
Description: Stores the possible statuses a single test can be in.
Columns: status_id (pk), status_name
Records:
1 - Ready
2 - Progress
3 - Complete
4 - Retest
-----
OBJECTIVE_
I am trying to display a matrix that will list all of the Products from the PRODUCTS table on the Y-axis (vertically) and the possible statuses on the X-axis (Horizontally). The matrix should then fill each column with the NUMBER of tests in that status for each product. And finally, I need to total them at the end. So visually something like this:

=======Ready=======Progress=======Complete=======Retest=======Total
Voice=====1==========0============1============0=========2
Internet===2==========1============1============0=========4
Cable=====1==========0============0============0=========1
Other=====0==========0============0============0=========0

I don't even know where to begin so, as I mentioned before, any assistance is GREATLY appreciated. I hope my explanation is clear enough.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 28 2010
Added on Apr 30 2010
9 comments
1,894 views