Advertisement

06.02.2008 at 01:20PM PDT, ID: 23451192
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

Need Help With SQL Query for Oracle RDB

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

Tags: , ,

I am trying to write a query that combines data from 2 different tables.

Table 1: POWERON
HEATNUMBER   BUCKETSEQUENCENO   CONSUMPTION  
 981011                      1                                   31  
 981011                      1                                  1269  
 981011                      1                                  15062  
 981011                      2                                  20327  
 981011                      3                                  577  
 981011                      3                                  36689  

Table 2: BUCKETS_HEAT
 HEAT_NUMBER   BUCKET_SEQUENCE   MATWEIGHTACT1   MATWEIGHTACT2  
 981011                      1                                          24150           20250  
 981011                      2                                          20100           30200  
 981011                      3                                          20050           20000

My goal is to get total CONSUMPTION and total weight (MATWEIGHTACT1 + MATWEIGHTACT2) for each BUCKET_SEQUENCE.

Here is my query:
SELECT B.HEATNUMBER, B.BUCKET_SEQUENCE,
sum(B.MATWEIGHTACT1 + B.MATWEIGHTACT2) as TOTAL_METALLIC_WEIGHT,
sum(P.CONSUMPTION) as POWER_CONSUMED
from BUCKETS_HEAT B, POWERON P
where
B.HEATNUMBER = P.HEATNUMBER
and B.BUCKET_SEQUENCE = P.BUCKET_SEQUENCE
group by B.HEATNUMBER, B.BUCKET_SEQUENCE, P.HEATNUMBER, P.BUCKET_SEQUENCE order by B.HEATNUMBER, B.BUCKETSEQUENCE;

This is the result:
 HEAT_NUMBER   BUCKET_SEQUENCE   TOTAL_METALLIC_WEIGHT         POWER_CONSUMED  
 981011                      1                                                      133200                  16362  
 981011                      2                                                        50300                  20327  
 981011                      3                                                         80100                 37266  

Here is whay I found:
POWER_CONSUMED for all 3 rows is correct.
Row 1 TOTAL_METTALIC_WEIGHT is 3X too large (Table POWERON has 3 records for BUCKET_SEQUENCE = 1).
Row 2 is correct (1 to 1 match in tables for BUCKET_SEQUENCE = 2).
Row 3 TOTAL_METALLIC_WEIGHT is 2X too large (Table POWERON has 2 records for BUCKET_SEQUENCE = 3).

Any suggestions?
Start Free Trial
[+][-]06.02.2008 at 01:30PM PDT, ID: 21695397

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: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_2_20070628