Solved

Help decode function multiple tables

Posted on 2004-09-11
5
911 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
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.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

749 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