Solved

Help decode function multiple tables

Posted on 2004-09-11
5
907 Views
Last Modified: 2008-01-09
Hi,

I need to run a calculation and plot graphs using a different application off the data I retrieve from two separate tables. The idea is to plot complaints generated from each of the sources in a common bar graph over a time period. For ex, If on a particular day, AOL generated 300 complaints and MSN generated, 200 complaints,  I would run a calculation that probably gave a result of 3 and 2 respectively for the two providers and on the bar graph, the aol complaints will be displayed from 0-3 and yahoo complaints from 3-5. This will repeat for all the days chosen.

I am trying to use DECODE to select the providers. This is my query:

select DECODE(T1.DOMAINNAME, 'aol.com',
         DECODE(T2.DOMAINNAME, 'aol.com',    ((T1.TOTAL_COMPLAINTS)/T2.SENT/1000000)))
                  )as y#COMPLAINTRATIO                          
FROM  TABLE1 T1, TABLE2 T2
WHERE  TRUNC(T2.SENT_DATE) = to_date('08/12/2004','MM/DD/YYYY')
AND TRUNC(T1.SENT_DATE) = to_date('08/12/2004','MM/DD/YYYY')

What I seem to be getting is a some sort of a sum and not the answer for aol for that particular day. I cannot achieve the same using where clause for the reasons mentioned above.

Please help!

Thank you,
Pratibha
0
Comment
Question by:pratibharao
5 Comments
 
LVL 7

Expert Comment

by:yoren
ID: 12037438
I'm not sure I understand. What info does table 1 have versus table 2?
0
 
LVL 4

Expert Comment

by:mottor
ID: 12037873
What is in this tables?
Where is your join condition?
0
 

Accepted Solution

by:
Captive1180 earned 100 total points
ID: 12131808
Try this

I think you wanna to something like this:

You have a column which has diff values in the form of  'aol.com' or it may be 'msn.com' etc.
Now according to this values you wanna perform some calculation.

You the structure of you decode function should be something like this
decode(table.column name,value to be checked,operation to be performed if the 2nd parameter is true)

So it should be something like this:

select DECODE(T1.DOMAINNAME, 'aol.com',
                      T2.DOMAINNAME, 'aol.com',T1.TOTAL_COMPLAINTS)/T2.SENT/1000000
                      )as y#COMPLAINTRATIO                      
FROM  TABLE1 T1, TABLE2 T2
WHERE  TRUNC(T2.SENT_DATE) = to_date('08/12/2004','MM/DD/YYYY')
AND TRUNC(T1.SENT_DATE) = to_date('08/12/2004','MM/DD/YYYY')

So do make some changes according to your need ,but keep in mind the decode function structure.

All the best
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now