Using Oracle 9i.
I have a table that stores the records in the following fashion:
I wish to return the data like this:
Here is my current SQL
The problem is that not all prod IDs will contain values for all attributes (Thickness, Drop, Height, etc...). If that is the case, no records are returned for the ProdID.
Any ideas? What is the best approach for this?
thanks for your time!
I have a table that stores the records in the following fashion:
Code:
prodID | sample | attribute | value
-----------------------------------
1445a | 1 | Thickness | 13.9
1445a | 2 | Thickness | 14
1445a | 3 | Thickness | 13.8
1445a | 1 | Drop | 0
1445a | 2 | Drop | .1
1445a | 3 | Drop | .1
1445a | 1 | Height | .1
1445a | 2 | Height | 1
1445a | 3 | Height | 1
I wish to return the data like this:
Code:
prodID | sample | Thickness | Drop | Height
-------------------------------------------------
1445a | 1 | 13.9 | 0 | .1
1445a | 2 | 14 | .1 | 1
1445a | 3 | 13.8 | .1 | 1
Here is my current SQL
Code:
SELECT ad.prodID, ad.sample, ad1.value as Thickness, ad2.value as Drop, ad3.value as Height
FROM mv_audit_data ad,
mv_audit_data ad1,
mv_audit_data ad2,
mv_audit_data ad3
where ad.prodID = <VALUE>
and ad.sample = ad1.sample
and ad.sample = ad2.sample
and ad.sample = ad3.sample
and ad.prodID = ad1.prodID
and ad.prodID = ad2.prodID
and ad.prodID = ad3.prodID
and ad1.attribute = 'Thickness'
and ad2.attribute = 'Drop'
and ad3.attribute = 'Height'
group by ad.prodID, ad.sample, ad1.value, ad2.value, ad3.value
The problem is that not all prod IDs will contain values for all attributes (Thickness, Drop, Height, etc...). If that is the case, no records are returned for the ProdID.
Any ideas? What is the best approach for this?
thanks for your time!