Advertisement

07.07.2008 at 01:22PM PDT, ID: 23544650
[x]
Attachment Details

Need Help With SQL Query for Oracle RDB (Part 2)

Asked by sainiak in SQL Query Syntax, Databases Miscellaneous, PL / SQL

Tags: Oracle, Oracle RDB, SQL Query

This is a follow up to a previous question (search on the question title).

Table 1: POWERON
HEATNUMBER   BUCKETSEQUENCE   CONSUMPTION  
 981011                      1                                   100  
 981011                      1                                   200  
 981011                      1                                   300  
 981011                      2                                   400  
 981011                      3                                   500  
 981011                      3                                   600  

Table 2: BUCKETS_HEAT
HEATNUMBER   BUCKETSEQUENCE   MATWEIGHTACT1   MATWEIGHTACT2  
 981011                      1                                          10000           20000  
 981011                      2                                          30000           40000  
 981011                      3                                          50000           60000

My goal was to get total CONSUMPTION and TOTAL_METALLIC_WEIGHT (MATWEIGHTACT1 + MATWEIGHTACT2) for each BUCKETSEQUENCE.

Here is the query that works:

SELECT b.heatnumber as HEAT_NUMBER,                  
b.bucketsequence as BUCKET_SEQUENCE,          
sum(b.matweightact1  + b.matweightact2 ) as TOTAL_METALLIC_WEIGHT,
sum(p.consumption) as POWER_CONSUMED
from buckets_heat b,
(select heatnumber, bucketsequence, sum(consumption) consumption  from poweron  group by heatnumber, bucketsequence ) p where b.heatnumber = '981011'
and b.heatnumber = p.heatnumber
and b.bucketsequence = p.bucketsequence group by b.heatnumber,
         b.bucketsequence,
         p.heatnumber,  
         p.bucketsequence
order by b.heatnumber,
         b.bucketsequence;

This is the result:
 HEAT_NUMBER   BUCKET_SEQUENCE   TOTAL_METALLIC_WEIGHT         POWER_CONSUMED  
 981011                      1                                                      30000                  600  
 981011                      2                                                      70000                  400  
 981011                      3                                                     110000                 1100  

This solution worked perfectly.  Now the problem:

A new constraint is to only include a material of Type 1 from this table...

Table 3: TABMAT
MATCODE   TYPE
123              1
456              2

Table BUCKETS_HEAT has MATCODE1 and MATCODE2 fields corresponding to the weight above.

Table 2: BUCKETS_HEAT
HEATNUMBER   BUCKETSEQUENCE   MATWEIGHTACT1   MATCODE1    MATWEIGHTACT2     MATCODE2  
 981011                      1                                          10000    123                 20000                        456  
 981011                      2                                          30000    456                 40000                        123  
 981011                      3                                          50000    123                 60000                        456

So the new result should look like this:
 HEAT_NUMBER   BUCKET_SEQUENCE   TOTAL_METALLIC_WEIGHT         POWER_CONSUMED  
 981011                      1                                                      10000                  600  
 981011                      2                                                      40000                  400  
 981011                      3                                                      50000                 1100  

where the weight from material 456 is excluded from the total.

Thanks in advance.Start Free Trial
[+][-]07.07.2008 at 01:37PM PDT, ID: 21948454

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: SQL Query Syntax, Databases Miscellaneous, PL / SQL
Tags: Oracle, Oracle RDB, SQL Query
Sign Up Now!
Solution Provided By: rbrooker
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.08.2008 at 01:17AM PDT, ID: 21951836

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.08.2008 at 07:02AM PDT, ID: 21953901

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.08.2008 at 07:32AM PDT, ID: 21954193

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.08.2008 at 08:22AM PDT, ID: 21954682

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.08.2008 at 11:58AM PDT, ID: 21956911

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.08.2008 at 07:27PM PDT, ID: 21960161

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_Related_20080208