dbTalk Databases Forums  

Query

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


Discuss Query in the comp.databases.oracle.misc forum.



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

Default Query - 01-24-2011 , 09:50 AM






Hi,

I need to create a very strange query. I'm sure it can be done, maybe
with analytical functions or something, but I need help. We are on
10g R2.

Say I have some data like this:

ID TRAN_DATE
ABC 1/1/2010
DEF 1/1/2010
GHI 2/3/2010
V.JKI 2/3/2010

Now, what I want is a total count of the record set AND a count to all
ID's that start with 'V.'. But, other criteria is applied to the
entire query.

SELECT COUNT(*) OVER () total, ...........
WHERE tran_date > '01-DEC-09';

SPLIT DATE TOTAL COUNT V.
1/1/2010 2 0
2/3/2010 2 1



So, I applying a set of criteria to the entire result set. Then,
within that, I want a count of the total record set, plus another
column that tells me the count of ID's that start with 'V.' from
within the same record set that had the date criteria applied.

I am hoping to only issue the date criteria once. Inline tables,
probably, analytical functions, probably, but, 2 sets of criteria to
the same result set. Seems a bit impossible.

This query will create a materialized view.......

Hope this all makes sense.

Thanks!

Reply With Quote
  #2  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: Query - 01-24-2011 , 10:11 AM






On 2011-01-24 16:50, The Magnet wrote:
Quote:
Hi,

I need to create a very strange query. I'm sure it can be done, maybe
with analytical functions or something, but I need help. We are on
10g R2.

Say I have some data like this:

ID TRAN_DATE
ABC 1/1/2010
DEF 1/1/2010
GHI 2/3/2010
V.JKI 2/3/2010

Now, what I want is a total count of the record set AND a count to all
ID's that start with 'V.'. But, other criteria is applied to the
entire query.

SELECT COUNT(*) OVER () total, ...........
WHERE tran_date > '01-DEC-09';

SPLIT DATE TOTAL COUNT V.
1/1/2010 2 0
2/3/2010 2 1

Perhaps something like:

select tran_date as split_date,
count(1) as total,
count(case when id like 'V%' then 1 end) as count_v
from ...
group by tran_date
order by tran_date

will do?

/Lennart

[...]

Reply With Quote
  #3  
Old   
The Magnet
 
Posts: n/a

Default Re: Query - 01-24-2011 , 01:41 PM



On Jan 24, 10:11*am, Lennart Jonsson <erik.lennart.jons... (AT) gmail (DOT) com>
wrote:
Quote:
On 2011-01-24 16:50, The Magnet wrote:



Hi,

I need to create a very strange query. *I'm sure it can be done, maybe
with analytical functions or something, but I need help. *We are on
10g R2.

Say I have some data like this:

ID * * * * * * * * * * * * * * * *TRAN_DATE
ABC * * * * * * * * * * * * * * 1/1/2010
DEF * * * * * * * * * * * * * * 1/1/2010
GHI * * * * * * * * * * * * * * * 2/3/2010
V.JKI * * * * * * * * * * * * * *2/3/2010

Now, what I want is a total count of the record set AND a count to all
ID's that start with 'V.'. *But, other criteria is applied to the
entire query.

SELECT COUNT(*) OVER () total, ...........
WHERE tran_date > '01-DEC-09';

SPLIT DATE * * * * * * * * TOTAL * * * * * * COUNT V.
1/1/2010 * * * * * * * * * * * *2 * * * * * * * * * * *0
2/3/2010 * * * * * * * * * * * *2 * * * * * * * * * * *1

Perhaps something like:

select tran_date as split_date,
* * * *count(1) as total,
* * * *count(case when id like 'V%' then 1 end) as count_v
from ...
group by tran_date
order by tran_date

will do?

/Lennart

[...]
Works perfectly! Thanks! Always forgot about that CASE
statement.....

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.