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   
amerar@iwc.net
 
Posts: n/a

Default query - 05-06-2008 , 03:54 PM







This simple query is driving me nuts.

I have a simple table:

customer_id
action_date
action

I want to get a distinct count of customer_id where the action = 'A'
and the MAX action date is between 01/01/2005 and 03/01/2005.

This seems simple, and here is my query:

SELECT MAX(action_date) action_date, count(distinct(customer_id))
FROM email_product_hist
WHERE action = 'A'
AND action_date BETWEEN TO_DATE('01012005','MMDDYYYY') AND
TO_DATE('03312005','MMDDYYYY')
AND customer_id NOT IN (SELECT customer_id FROM customer_account);

But people are telling me that this does not render the correct
results.......is there something I am missing??

Thanks!

Reply With Quote
  #2  
Old   
Mark D Powell
 
Posts: n/a

Default Re: query - 05-07-2008 , 11:44 AM






On May 6, 4:54*pm, "ame... (AT) iwc (DOT) net" <ame... (AT) iwc (DOT) net> wrote:
Quote:
This simple query is driving me nuts.

I have a simple table:

customer_id
action_date
action

I want to get a distinct count of customer_id where the action = 'A'
and the MAX action date is between 01/01/2005 and 03/01/2005.

This seems simple, and here is my query:

SELECT MAX(action_date) action_date, count(distinct(customer_id))
FROM email_product_hist
WHERE action = 'A'
* AND action_date BETWEEN TO_DATE('01012005','MMDDYYYY') AND
TO_DATE('03312005','MMDDYYYY')
* AND customer_id NOT IN (SELECT customer_id FROM customer_account);

But people are telling me that this does not render the correct
results.......is there something I am missing??

Thanks!
I suspect you need to group your data by trunc(action_date) and
customer_id so you have a count of unique customers by date where the
other conditions are also true.

If you post a create table with a few rows of insert and show the
desired results perhaps someone will take the time to correct your
query.

You should always specific the full Oracle version and edition as
responses are often version specific.

HTH -- Mark D Powell --


Reply With Quote
  #3  
Old   
Mark D Powell
 
Posts: n/a

Default Re: query - 05-07-2008 , 11:44 AM



On May 6, 4:54*pm, "ame... (AT) iwc (DOT) net" <ame... (AT) iwc (DOT) net> wrote:
Quote:
This simple query is driving me nuts.

I have a simple table:

customer_id
action_date
action

I want to get a distinct count of customer_id where the action = 'A'
and the MAX action date is between 01/01/2005 and 03/01/2005.

This seems simple, and here is my query:

SELECT MAX(action_date) action_date, count(distinct(customer_id))
FROM email_product_hist
WHERE action = 'A'
* AND action_date BETWEEN TO_DATE('01012005','MMDDYYYY') AND
TO_DATE('03312005','MMDDYYYY')
* AND customer_id NOT IN (SELECT customer_id FROM customer_account);

But people are telling me that this does not render the correct
results.......is there something I am missing??

Thanks!
I suspect you need to group your data by trunc(action_date) and
customer_id so you have a count of unique customers by date where the
other conditions are also true.

If you post a create table with a few rows of insert and show the
desired results perhaps someone will take the time to correct your
query.

You should always specific the full Oracle version and edition as
responses are often version specific.

HTH -- Mark D Powell --


Reply With Quote
  #4  
Old   
Mark D Powell
 
Posts: n/a

Default Re: query - 05-07-2008 , 11:44 AM



On May 6, 4:54*pm, "ame... (AT) iwc (DOT) net" <ame... (AT) iwc (DOT) net> wrote:
Quote:
This simple query is driving me nuts.

I have a simple table:

customer_id
action_date
action

I want to get a distinct count of customer_id where the action = 'A'
and the MAX action date is between 01/01/2005 and 03/01/2005.

This seems simple, and here is my query:

SELECT MAX(action_date) action_date, count(distinct(customer_id))
FROM email_product_hist
WHERE action = 'A'
* AND action_date BETWEEN TO_DATE('01012005','MMDDYYYY') AND
TO_DATE('03312005','MMDDYYYY')
* AND customer_id NOT IN (SELECT customer_id FROM customer_account);

But people are telling me that this does not render the correct
results.......is there something I am missing??

Thanks!
I suspect you need to group your data by trunc(action_date) and
customer_id so you have a count of unique customers by date where the
other conditions are also true.

If you post a create table with a few rows of insert and show the
desired results perhaps someone will take the time to correct your
query.

You should always specific the full Oracle version and edition as
responses are often version specific.

HTH -- Mark D Powell --


Reply With Quote
  #5  
Old   
Mark D Powell
 
Posts: n/a

Default Re: query - 05-07-2008 , 11:44 AM



On May 6, 4:54*pm, "ame... (AT) iwc (DOT) net" <ame... (AT) iwc (DOT) net> wrote:
Quote:
This simple query is driving me nuts.

I have a simple table:

customer_id
action_date
action

I want to get a distinct count of customer_id where the action = 'A'
and the MAX action date is between 01/01/2005 and 03/01/2005.

This seems simple, and here is my query:

SELECT MAX(action_date) action_date, count(distinct(customer_id))
FROM email_product_hist
WHERE action = 'A'
* AND action_date BETWEEN TO_DATE('01012005','MMDDYYYY') AND
TO_DATE('03312005','MMDDYYYY')
* AND customer_id NOT IN (SELECT customer_id FROM customer_account);

But people are telling me that this does not render the correct
results.......is there something I am missing??

Thanks!
I suspect you need to group your data by trunc(action_date) and
customer_id so you have a count of unique customers by date where the
other conditions are also true.

If you post a create table with a few rows of insert and show the
desired results perhaps someone will take the time to correct your
query.

You should always specific the full Oracle version and edition as
responses are often version specific.

HTH -- Mark D Powell --


Reply With Quote
  #6  
Old   
amerar@iwc.net
 
Posts: n/a

Default Re: query - 05-07-2008 , 12:50 PM



On May 7, 11:44 am, Mark D Powell <Mark.Pow... (AT) eds (DOT) com> wrote:
Quote:
On May 6, 4:54 pm, "ame... (AT) iwc (DOT) net" <ame... (AT) iwc (DOT) net> wrote:



This simple query is driving me nuts.

I have a simple table:

customer_id
action_date
action

I want to get a distinct count of customer_id where the action = 'A'
and the MAX action date is between 01/01/2005 and 03/01/2005.

This seems simple, and here is my query:

SELECT MAX(action_date) action_date, count(distinct(customer_id))
FROM email_product_hist
WHERE action = 'A'
AND action_date BETWEEN TO_DATE('01012005','MMDDYYYY') AND
TO_DATE('03312005','MMDDYYYY')
AND customer_id NOT IN (SELECT customer_id FROM customer_account);

But people are telling me that this does not render the correct
results.......is there something I am missing??

Thanks!

I suspect you need to group your data by trunc(action_date) and
customer_id so you have a count of unique customers by date where the
other conditions are also true.

If you post a create table with a few rows of insert and show the
desired results perhaps someone will take the time to correct your
query.

You should always specific the full Oracle version and edition as
responses are often version specific.

HTH -- Mark D Powell --
Thanks for the feedback Mark. Say I have this data:

Customer Id Action Date Status
---------------------------------------
12345678 12/01/2005 Active
12345678 03/01/2005 Inactive
12345678 01/01/2005 Active
24568123 11/15/2005 Inactive
33445566 03/01/2006 Active
32548798 02/28/2005 Active
77777733 02/15/2005 Inactive
77777733 02/01/2005 Active

Now, basically I want to ignore row# 5 as it falls outside my range.
I also want to ignore row 4 as his status is inactive.
I want to include rows 6 as he is active, and row 1, as his MAX date
shows him active.

That is the key, that his MAX date still shows him active.
Row #7 will be ignored because his MAX date shows him as inactive....

Does that make more sense? And, we are on 10g R2....

Thanks again!

John


Reply With Quote
  #7  
Old   
amerar@iwc.net
 
Posts: n/a

Default Re: query - 05-07-2008 , 12:50 PM



On May 7, 11:44 am, Mark D Powell <Mark.Pow... (AT) eds (DOT) com> wrote:
Quote:
On May 6, 4:54 pm, "ame... (AT) iwc (DOT) net" <ame... (AT) iwc (DOT) net> wrote:



This simple query is driving me nuts.

I have a simple table:

customer_id
action_date
action

I want to get a distinct count of customer_id where the action = 'A'
and the MAX action date is between 01/01/2005 and 03/01/2005.

This seems simple, and here is my query:

SELECT MAX(action_date) action_date, count(distinct(customer_id))
FROM email_product_hist
WHERE action = 'A'
AND action_date BETWEEN TO_DATE('01012005','MMDDYYYY') AND
TO_DATE('03312005','MMDDYYYY')
AND customer_id NOT IN (SELECT customer_id FROM customer_account);

But people are telling me that this does not render the correct
results.......is there something I am missing??

Thanks!

I suspect you need to group your data by trunc(action_date) and
customer_id so you have a count of unique customers by date where the
other conditions are also true.

If you post a create table with a few rows of insert and show the
desired results perhaps someone will take the time to correct your
query.

You should always specific the full Oracle version and edition as
responses are often version specific.

HTH -- Mark D Powell --
Thanks for the feedback Mark. Say I have this data:

Customer Id Action Date Status
---------------------------------------
12345678 12/01/2005 Active
12345678 03/01/2005 Inactive
12345678 01/01/2005 Active
24568123 11/15/2005 Inactive
33445566 03/01/2006 Active
32548798 02/28/2005 Active
77777733 02/15/2005 Inactive
77777733 02/01/2005 Active

Now, basically I want to ignore row# 5 as it falls outside my range.
I also want to ignore row 4 as his status is inactive.
I want to include rows 6 as he is active, and row 1, as his MAX date
shows him active.

That is the key, that his MAX date still shows him active.
Row #7 will be ignored because his MAX date shows him as inactive....

Does that make more sense? And, we are on 10g R2....

Thanks again!

John


Reply With Quote
  #8  
Old   
amerar@iwc.net
 
Posts: n/a

Default Re: query - 05-07-2008 , 12:50 PM



On May 7, 11:44 am, Mark D Powell <Mark.Pow... (AT) eds (DOT) com> wrote:
Quote:
On May 6, 4:54 pm, "ame... (AT) iwc (DOT) net" <ame... (AT) iwc (DOT) net> wrote:



This simple query is driving me nuts.

I have a simple table:

customer_id
action_date
action

I want to get a distinct count of customer_id where the action = 'A'
and the MAX action date is between 01/01/2005 and 03/01/2005.

This seems simple, and here is my query:

SELECT MAX(action_date) action_date, count(distinct(customer_id))
FROM email_product_hist
WHERE action = 'A'
AND action_date BETWEEN TO_DATE('01012005','MMDDYYYY') AND
TO_DATE('03312005','MMDDYYYY')
AND customer_id NOT IN (SELECT customer_id FROM customer_account);

But people are telling me that this does not render the correct
results.......is there something I am missing??

Thanks!

I suspect you need to group your data by trunc(action_date) and
customer_id so you have a count of unique customers by date where the
other conditions are also true.

If you post a create table with a few rows of insert and show the
desired results perhaps someone will take the time to correct your
query.

You should always specific the full Oracle version and edition as
responses are often version specific.

HTH -- Mark D Powell --
Thanks for the feedback Mark. Say I have this data:

Customer Id Action Date Status
---------------------------------------
12345678 12/01/2005 Active
12345678 03/01/2005 Inactive
12345678 01/01/2005 Active
24568123 11/15/2005 Inactive
33445566 03/01/2006 Active
32548798 02/28/2005 Active
77777733 02/15/2005 Inactive
77777733 02/01/2005 Active

Now, basically I want to ignore row# 5 as it falls outside my range.
I also want to ignore row 4 as his status is inactive.
I want to include rows 6 as he is active, and row 1, as his MAX date
shows him active.

That is the key, that his MAX date still shows him active.
Row #7 will be ignored because his MAX date shows him as inactive....

Does that make more sense? And, we are on 10g R2....

Thanks again!

John


Reply With Quote
  #9  
Old   
amerar@iwc.net
 
Posts: n/a

Default Re: query - 05-07-2008 , 12:50 PM



On May 7, 11:44 am, Mark D Powell <Mark.Pow... (AT) eds (DOT) com> wrote:
Quote:
On May 6, 4:54 pm, "ame... (AT) iwc (DOT) net" <ame... (AT) iwc (DOT) net> wrote:



This simple query is driving me nuts.

I have a simple table:

customer_id
action_date
action

I want to get a distinct count of customer_id where the action = 'A'
and the MAX action date is between 01/01/2005 and 03/01/2005.

This seems simple, and here is my query:

SELECT MAX(action_date) action_date, count(distinct(customer_id))
FROM email_product_hist
WHERE action = 'A'
AND action_date BETWEEN TO_DATE('01012005','MMDDYYYY') AND
TO_DATE('03312005','MMDDYYYY')
AND customer_id NOT IN (SELECT customer_id FROM customer_account);

But people are telling me that this does not render the correct
results.......is there something I am missing??

Thanks!

I suspect you need to group your data by trunc(action_date) and
customer_id so you have a count of unique customers by date where the
other conditions are also true.

If you post a create table with a few rows of insert and show the
desired results perhaps someone will take the time to correct your
query.

You should always specific the full Oracle version and edition as
responses are often version specific.

HTH -- Mark D Powell --
Thanks for the feedback Mark. Say I have this data:

Customer Id Action Date Status
---------------------------------------
12345678 12/01/2005 Active
12345678 03/01/2005 Inactive
12345678 01/01/2005 Active
24568123 11/15/2005 Inactive
33445566 03/01/2006 Active
32548798 02/28/2005 Active
77777733 02/15/2005 Inactive
77777733 02/01/2005 Active

Now, basically I want to ignore row# 5 as it falls outside my range.
I also want to ignore row 4 as his status is inactive.
I want to include rows 6 as he is active, and row 1, as his MAX date
shows him active.

That is the key, that his MAX date still shows him active.
Row #7 will be ignored because his MAX date shows him as inactive....

Does that make more sense? And, we are on 10g R2....

Thanks again!

John


Reply With Quote
  #10  
Old   
gazzag
 
Posts: n/a

Default Re: query - 05-08-2008 , 06:32 AM



On 7 May, 18:50, "ame... (AT) iwc (DOT) net" <ame... (AT) iwc (DOT) net> wrote:
Quote:
Thanks for the feedback Mark. *Say I have this data:

Customer Id * * *Action Date * * Status
---------------------------------------
12345678 * * * *12/01/2005 * * * Active
12345678 * * * *03/01/2005 * * * Inactive
12345678 * * * *01/01/2005 * * * Active
24568123 * * * *11/15/2005 * * * Inactive
33445566 * * * *03/01/2006 * * * Active
32548798 * * * *02/28/2005 * * * Active
77777733 * * * *02/15/2005 * * * Inactive
77777733 * * * *02/01/2005 * * * Active

Now, basically I want to ignore row# 5 as it falls outside my range.
I also want to ignore row 4 as his status is inactive.
I want to include rows 6 as he is active, and row 1, as his MAX date
shows him active.

That is the key, that his MAX date still shows him active.
Row #7 will be ignored because his MAX date shows him as inactive....

Does that make more sense? *And, we are on 10g R2....

Thanks again!

John
As Mark said, post the relevant CREATE TABLE script, together with an
INSERT script to populate the table and someone will be more inclined
to help with your query.

HTH

-g


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.