Solved

Help decode function multiple tables

Posted on 2004-09-11
5
910 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Query 34 115
Oracle SQL Select unique values from two columns 4 66
error in my cursor 5 41
UTL_FILE invalid file operation 5 24
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…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

789 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