dbTalk Databases Forums  

Help with hard query

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Help with hard query in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
The Magnet
 
Posts: n/a

Default Help with hard query - 03-03-2011 , 04:46 PM






Hi,

I have this query (below), it is supposed to return 2 columns from
different tables using subqueries. So, each query is a column. If
data is found in both columns, data is returned. If one of the
queries has no data, nothing is returned.

What I want is if one of the subqueries has no data because the WHERE
fails, it should return NULL for that column value:

In the below query, if the query from revision_events_count_mv returns
data and the query from guidance_events_count_mv returns none, the
query should do just that, return data for column 1 and null for
column 2.

Help anyone?

SELECT SYSDATE event_date, revisions, guidance
FROM (SELECT revisions, guidance
FROM ((SELECT SUM(revisions) OVER (PARTITION BY event_date)
revisions
FROM revision_events_count_mv
WHERE event_date = TO_DATE('01312011','MMDDYYYY'))),
(SELECT SUM(guidance) OVER (PARTITION BY event_date)
guidance
FROM guidance_events_count_mv
WHERE event_date = TO_DATE('04052009','MMDDYYYY')));

Reply With Quote
  #2  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: Help with hard query - 03-04-2011 , 01:57 AM






On 3 Mrz., 23:46, The Magnet <a... (AT) unsu (DOT) com> wrote:
Quote:
Hi,

I have this query (below), it is supposed to return 2 columns from
different tables using subqueries. *So, each query is a column. *If
data is found in both columns, data is returned. *If one of the
queries has no data, nothing is returned.

What I want is if one of the subqueries has no data because the WHERE
fails, it should return NULL for that column value:

In the below query, if the query from revision_events_count_mv returns
data and the query from guidance_events_count_mv returns none, the
query should do just that, return data for column 1 and null for
column 2.

Help anyone?

* SELECT SYSDATE event_date, revisions, guidance
* FROM (SELECT revisions, guidance
* * * * FROM ((SELECT SUM(revisions) OVER (PARTITION BY event_date)
revisions
* * * * * * * *FROM revision_events_count_mv
* * * * * * * *WHERE event_date = TO_DATE('01312011','MMDDYYYY'))),
* * * * * * * (SELECT SUM(guidance) OVER (PARTITION BY event_date)
guidance
* * * * * * * *FROM guidance_events_count_mv
* * * * * * * *WHERE event_date = TO_DATE('04052009','MMDDYYYY')));
select
sysdate event_date,
(select sum(revisions)
from revision_events_count_mv
where event_date=date '2009-04-05') revisions,
(select sum(guidance)
from guidance_events_count_mv
where event_date=date '2011-01-31') guidance
from dual
/

Best regards

Maxim

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.