Fiat, You can accomplish what you want with the use of Oracle's outer join functionality. In the sample, below, the outer-join operator that I use, (+), will work on any version of Oracle. (There is other outer-join syntax available in more recent versions of Oracle, but I'll not illustrate the alternate syntax here.) I've added one row of data to simulate your case of a sample with missing attributes. I've also retained your original code for the most part, added the outer-join operator, and used an in-line view for your driver table ("ad") just because it seemed more efficient: CODESQL> select * from mv_audit_data;
PRODI 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 1445a 4 Drop .15
10 rows selected.
SELECT ad.prodID, ad.sample, ad1.value as Thickness, ad2.value as Drop_val, ad3.value as Height FROM (select distinct prodid, sample from mv_audit_data where prodid = '1445a') ad, mv_audit_data ad1, mv_audit_data ad2, mv_audit_data ad3 where 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 order by prodid, sample /
PRODI SAMPLE THICKNESS DROP_VAL HEIGHT ----- ---------- ---------- ---------- ---------- 1445a 1 13.9 0 .1 1445a 2 14 .1 1 1445a 3 13.8 .1 1 1445a 4 .15
4 rows selected. Rather than my answering questions here that you might not have, I'll wait for you to ask questions about this technique if you actually have questions. Mufasa (aka Dave of Sandy, Utah, USA) [I provide low-cost, remote Database Administration services: www.dasages.com] "Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty." |
|