dbTalk Databases Forums  

Group By?

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


Discuss Group By? in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
amerar@iwc.net
 
Posts: n/a

Default Group By? - 02-08-2008 , 01:21 PM







Hi All,

I have the following query. For a few records, it returns duplicate
CUSTOMER_ID's, though the rest of the record values are different.

I want 1 record per CUSTOMER_ID, regardless of the other values.

SELECT co.customer_id c_id, engine.calc_end_date (co.order_date,
p.quantity, p.quantity_uom) end_date,
DECODE(ns.subscr_type, 'Trial', 'Trial', 'Test', 'Trial',
'Paid') subscr_type
FROM engine.customer_order co, engine.order_line ol, engine.product
p, product.newsletter_subscription ns
WHERE co.order_id = ol.order_id
AND ol.product_id = p.product_id
AND p.code = ns.code
AND p.subproduct_id IN (197, 202, 209, 216, 220, 222)
AND ol.status = 'Active'
ORDER BY co.customer_id;

Still working a solution.

Reply With Quote
  #2  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: Group By? - 02-08-2008 , 02:45 PM






Comments embedded.
On Feb 8, 1:21*pm, "ame... (AT) iwc (DOT) net" <ame... (AT) iwc (DOT) net> wrote:
Quote:
Hi All,

I have the following query. *For a few records, it returns duplicate
CUSTOMER_ID's, though the rest of the record values are different.

So the query is returning distinct records.

Quote:
I want 1 record per CUSTOMER_ID, regardless of the other values.
Why? What is the purpose of that requirement?

Quote:
* *SELECT co.customer_id c_id, engine.calc_end_date (co.order_date,
p.quantity, p.quantity_uom) end_date,
* * * * * DECODE(ns.subscr_type, 'Trial', 'Trial', 'Test', 'Trial',
'Paid') subscr_type
* *FROM engine.customer_order co, engine.order_line ol, engine.product
p, product.newsletter_subscription ns
* *WHERE co.order_id = ol.order_id
* *AND ol.product_id = p.product_id
* *AND p.code = ns.code
* *AND p.subproduct_id IN (197, 202, 209, 216, 220, 222)
* *AND ol.status = 'Active'
* *ORDER BY co.customer_id;

Still working a solution.
Possibly you haven't tried hard enough:

select c_id, max(end_date), max(subscriber_type)
from
( SELECT co.customer_id c_id, engine.calc_end_date (co.order_date,
p.quantity, p.quantity_uom) end_date,
DECODE(ns.subscr_type, 'Trial', 'Trial', 'Test', 'Trial',
'Paid') subscr_type
FROM engine.customer_order co, engine.order_line ol,
engine.product
p, product.newsletter_subscription ns
WHERE co.order_id = ol.order_id
AND ol.product_id = p.product_id
AND p.code = ns.code
AND p.subproduct_id IN (197, 202, 209, 216, 220, 222)
AND ol.status = 'Active' )
group by c_id
order by c_id;

The query above should provide you one record per customer id; how
useful that data will be remains to be seen.


David Fitzjarrell


Reply With Quote
  #3  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: Group By? - 02-08-2008 , 02:45 PM



Comments embedded.
On Feb 8, 1:21*pm, "ame... (AT) iwc (DOT) net" <ame... (AT) iwc (DOT) net> wrote:
Quote:
Hi All,

I have the following query. *For a few records, it returns duplicate
CUSTOMER_ID's, though the rest of the record values are different.

So the query is returning distinct records.

Quote:
I want 1 record per CUSTOMER_ID, regardless of the other values.
Why? What is the purpose of that requirement?

Quote:
* *SELECT co.customer_id c_id, engine.calc_end_date (co.order_date,
p.quantity, p.quantity_uom) end_date,
* * * * * DECODE(ns.subscr_type, 'Trial', 'Trial', 'Test', 'Trial',
'Paid') subscr_type
* *FROM engine.customer_order co, engine.order_line ol, engine.product
p, product.newsletter_subscription ns
* *WHERE co.order_id = ol.order_id
* *AND ol.product_id = p.product_id
* *AND p.code = ns.code
* *AND p.subproduct_id IN (197, 202, 209, 216, 220, 222)
* *AND ol.status = 'Active'
* *ORDER BY co.customer_id;

Still working a solution.
Possibly you haven't tried hard enough:

select c_id, max(end_date), max(subscriber_type)
from
( SELECT co.customer_id c_id, engine.calc_end_date (co.order_date,
p.quantity, p.quantity_uom) end_date,
DECODE(ns.subscr_type, 'Trial', 'Trial', 'Test', 'Trial',
'Paid') subscr_type
FROM engine.customer_order co, engine.order_line ol,
engine.product
p, product.newsletter_subscription ns
WHERE co.order_id = ol.order_id
AND ol.product_id = p.product_id
AND p.code = ns.code
AND p.subproduct_id IN (197, 202, 209, 216, 220, 222)
AND ol.status = 'Active' )
group by c_id
order by c_id;

The query above should provide you one record per customer id; how
useful that data will be remains to be seen.


David Fitzjarrell


Reply With Quote
  #4  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: Group By? - 02-08-2008 , 02:45 PM



Comments embedded.
On Feb 8, 1:21*pm, "ame... (AT) iwc (DOT) net" <ame... (AT) iwc (DOT) net> wrote:
Quote:
Hi All,

I have the following query. *For a few records, it returns duplicate
CUSTOMER_ID's, though the rest of the record values are different.

So the query is returning distinct records.

Quote:
I want 1 record per CUSTOMER_ID, regardless of the other values.
Why? What is the purpose of that requirement?

Quote:
* *SELECT co.customer_id c_id, engine.calc_end_date (co.order_date,
p.quantity, p.quantity_uom) end_date,
* * * * * DECODE(ns.subscr_type, 'Trial', 'Trial', 'Test', 'Trial',
'Paid') subscr_type
* *FROM engine.customer_order co, engine.order_line ol, engine.product
p, product.newsletter_subscription ns
* *WHERE co.order_id = ol.order_id
* *AND ol.product_id = p.product_id
* *AND p.code = ns.code
* *AND p.subproduct_id IN (197, 202, 209, 216, 220, 222)
* *AND ol.status = 'Active'
* *ORDER BY co.customer_id;

Still working a solution.
Possibly you haven't tried hard enough:

select c_id, max(end_date), max(subscriber_type)
from
( SELECT co.customer_id c_id, engine.calc_end_date (co.order_date,
p.quantity, p.quantity_uom) end_date,
DECODE(ns.subscr_type, 'Trial', 'Trial', 'Test', 'Trial',
'Paid') subscr_type
FROM engine.customer_order co, engine.order_line ol,
engine.product
p, product.newsletter_subscription ns
WHERE co.order_id = ol.order_id
AND ol.product_id = p.product_id
AND p.code = ns.code
AND p.subproduct_id IN (197, 202, 209, 216, 220, 222)
AND ol.status = 'Active' )
group by c_id
order by c_id;

The query above should provide you one record per customer id; how
useful that data will be remains to be seen.


David Fitzjarrell


Reply With Quote
  #5  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: Group By? - 02-08-2008 , 02:45 PM



Comments embedded.
On Feb 8, 1:21*pm, "ame... (AT) iwc (DOT) net" <ame... (AT) iwc (DOT) net> wrote:
Quote:
Hi All,

I have the following query. *For a few records, it returns duplicate
CUSTOMER_ID's, though the rest of the record values are different.

So the query is returning distinct records.

Quote:
I want 1 record per CUSTOMER_ID, regardless of the other values.
Why? What is the purpose of that requirement?

Quote:
* *SELECT co.customer_id c_id, engine.calc_end_date (co.order_date,
p.quantity, p.quantity_uom) end_date,
* * * * * DECODE(ns.subscr_type, 'Trial', 'Trial', 'Test', 'Trial',
'Paid') subscr_type
* *FROM engine.customer_order co, engine.order_line ol, engine.product
p, product.newsletter_subscription ns
* *WHERE co.order_id = ol.order_id
* *AND ol.product_id = p.product_id
* *AND p.code = ns.code
* *AND p.subproduct_id IN (197, 202, 209, 216, 220, 222)
* *AND ol.status = 'Active'
* *ORDER BY co.customer_id;

Still working a solution.
Possibly you haven't tried hard enough:

select c_id, max(end_date), max(subscriber_type)
from
( SELECT co.customer_id c_id, engine.calc_end_date (co.order_date,
p.quantity, p.quantity_uom) end_date,
DECODE(ns.subscr_type, 'Trial', 'Trial', 'Test', 'Trial',
'Paid') subscr_type
FROM engine.customer_order co, engine.order_line ol,
engine.product
p, product.newsletter_subscription ns
WHERE co.order_id = ol.order_id
AND ol.product_id = p.product_id
AND p.code = ns.code
AND p.subproduct_id IN (197, 202, 209, 216, 220, 222)
AND ol.status = 'Active' )
group by c_id
order by c_id;

The query above should provide you one record per customer id; how
useful that data will be remains to be seen.


David Fitzjarrell


Reply With Quote
  #6  
Old   
shakespeare
 
Posts: n/a

Default Re: Group By? - 02-08-2008 , 02:53 PM




<amerar (AT) iwc (DOT) net> schreef in bericht
news:1c04d8cf-f3da-4b8b-9b0d-8e451c94c762 (AT) h11g2000prf (DOT) googlegroups.com...
Quote:
Hi All,

I have the following query. For a few records, it returns duplicate
CUSTOMER_ID's, though the rest of the record values are different.

I want 1 record per CUSTOMER_ID, regardless of the other values.

SELECT co.customer_id c_id, engine.calc_end_date (co.order_date,
p.quantity, p.quantity_uom) end_date,
DECODE(ns.subscr_type, 'Trial', 'Trial', 'Test', 'Trial',
'Paid') subscr_type
FROM engine.customer_order co, engine.order_line ol, engine.product
p, product.newsletter_subscription ns
WHERE co.order_id = ol.order_id
AND ol.product_id = p.product_id
AND p.code = ns.code
AND p.subproduct_id IN (197, 202, 209, 216, 220, 222)
AND ol.status = 'Active'
ORDER BY co.customer_id;

Still working a solution.
Then DON'T select the other values (if you don't care about them)....

Shakespeare




Reply With Quote
  #7  
Old   
shakespeare
 
Posts: n/a

Default Re: Group By? - 02-08-2008 , 02:53 PM




<amerar (AT) iwc (DOT) net> schreef in bericht
news:1c04d8cf-f3da-4b8b-9b0d-8e451c94c762 (AT) h11g2000prf (DOT) googlegroups.com...
Quote:
Hi All,

I have the following query. For a few records, it returns duplicate
CUSTOMER_ID's, though the rest of the record values are different.

I want 1 record per CUSTOMER_ID, regardless of the other values.

SELECT co.customer_id c_id, engine.calc_end_date (co.order_date,
p.quantity, p.quantity_uom) end_date,
DECODE(ns.subscr_type, 'Trial', 'Trial', 'Test', 'Trial',
'Paid') subscr_type
FROM engine.customer_order co, engine.order_line ol, engine.product
p, product.newsletter_subscription ns
WHERE co.order_id = ol.order_id
AND ol.product_id = p.product_id
AND p.code = ns.code
AND p.subproduct_id IN (197, 202, 209, 216, 220, 222)
AND ol.status = 'Active'
ORDER BY co.customer_id;

Still working a solution.
Then DON'T select the other values (if you don't care about them)....

Shakespeare




Reply With Quote
  #8  
Old   
shakespeare
 
Posts: n/a

Default Re: Group By? - 02-08-2008 , 02:53 PM




<amerar (AT) iwc (DOT) net> schreef in bericht
news:1c04d8cf-f3da-4b8b-9b0d-8e451c94c762 (AT) h11g2000prf (DOT) googlegroups.com...
Quote:
Hi All,

I have the following query. For a few records, it returns duplicate
CUSTOMER_ID's, though the rest of the record values are different.

I want 1 record per CUSTOMER_ID, regardless of the other values.

SELECT co.customer_id c_id, engine.calc_end_date (co.order_date,
p.quantity, p.quantity_uom) end_date,
DECODE(ns.subscr_type, 'Trial', 'Trial', 'Test', 'Trial',
'Paid') subscr_type
FROM engine.customer_order co, engine.order_line ol, engine.product
p, product.newsletter_subscription ns
WHERE co.order_id = ol.order_id
AND ol.product_id = p.product_id
AND p.code = ns.code
AND p.subproduct_id IN (197, 202, 209, 216, 220, 222)
AND ol.status = 'Active'
ORDER BY co.customer_id;

Still working a solution.
Then DON'T select the other values (if you don't care about them)....

Shakespeare




Reply With Quote
  #9  
Old   
shakespeare
 
Posts: n/a

Default Re: Group By? - 02-08-2008 , 02:53 PM




<amerar (AT) iwc (DOT) net> schreef in bericht
news:1c04d8cf-f3da-4b8b-9b0d-8e451c94c762 (AT) h11g2000prf (DOT) googlegroups.com...
Quote:
Hi All,

I have the following query. For a few records, it returns duplicate
CUSTOMER_ID's, though the rest of the record values are different.

I want 1 record per CUSTOMER_ID, regardless of the other values.

SELECT co.customer_id c_id, engine.calc_end_date (co.order_date,
p.quantity, p.quantity_uom) end_date,
DECODE(ns.subscr_type, 'Trial', 'Trial', 'Test', 'Trial',
'Paid') subscr_type
FROM engine.customer_order co, engine.order_line ol, engine.product
p, product.newsletter_subscription ns
WHERE co.order_id = ol.order_id
AND ol.product_id = p.product_id
AND p.code = ns.code
AND p.subproduct_id IN (197, 202, 209, 216, 220, 222)
AND ol.status = 'Active'
ORDER BY co.customer_id;

Still working a solution.
Then DON'T select the other values (if you don't care about them)....

Shakespeare




Reply With Quote
  #10  
Old   
Isaac Blank
 
Posts: n/a

Default Re: Group By? - 02-08-2008 , 03:16 PM



select customer_id, end_date, subscr_type
from (
SELECT co.customer_id c_id, engine.calc_end_date (co.order_date,
p.quantity, p.quantity_uom) end_date,
DECODE(ns.subscr_type, 'Trial', 'Trial', 'Test', 'Trial',
'Paid') subscr_type, row_number() over (partition by customer_id order by
rowid) ordering
FROM engine.customer_order co, engine.order_line ol, engine.product
p, product.newsletter_subscription ns
WHERE co.order_id = ol.order_id
AND ol.product_id = p.product_id
AND p.code = ns.code
AND p.subproduct_id IN (197, 202, 209, 216, 220, 222)
AND ol.status = 'Active'
)
where ordering=1
ORDER BY customer_id;

<amerar (AT) iwc (DOT) net> wrote

Quote:
Hi All,

I have the following query. For a few records, it returns duplicate
CUSTOMER_ID's, though the rest of the record values are different.

I want 1 record per CUSTOMER_ID, regardless of the other values.

SELECT co.customer_id c_id, engine.calc_end_date (co.order_date,
p.quantity, p.quantity_uom) end_date,
DECODE(ns.subscr_type, 'Trial', 'Trial', 'Test', 'Trial',
'Paid') subscr_type
FROM engine.customer_order co, engine.order_line ol, engine.product
p, product.newsletter_subscription ns
WHERE co.order_id = ol.order_id
AND ol.product_id = p.product_id
AND p.code = ns.code
AND p.subproduct_id IN (197, 202, 209, 216, 220, 222)
AND ol.status = 'Active'
ORDER BY co.customer_id;

Still working a solution.


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.