|
|
|
|
|
|
| Author |
Message |
Jimmy *nix forums beginner
Joined: 22 Mar 2005
Posts: 39
|
Posted: Mon Feb 28, 2005 1:45 pm Post subject:
Re: complex? SQL time series problem
|
|
|
gmuldoonnospam@scu.edu.au says...
| Quote: | CREATE TABLE TEST3
(
C_SET VARCHAR2(25),
C_ID VARCHAR2(25),
STTS VARCHAR2(25),
S_DATE DATE,
E_DATE DATE
)
|
Could you possibly explain in more detail exactly what it is you want
and why?
Paul... |
|
| Back to top |
|
 |
Geoff M *nix forums beginner
Joined: 23 Feb 2005
Posts: 18
|
Posted: Mon Feb 21, 2005 4:44 am Post subject:
Re: complex? SQL time series problem
|
|
|
In article <1108737483.685588.220970@c13g2000cwb.googlegroups.com>,
Mark.Powell@eds.com says...
| Quote: | Geoff, I suspect that you have not described the problem correctly.
The answer I gave should work for the problem as you described it.
Obviously neither I nor Daniel understand correctly what it is you need
to do.
|
OK trying again ..
CREATE TABLE TEST3
(
C_SET VARCHAR2(25),
C_ID VARCHAR2(25),
STTS VARCHAR2(25),
S_DATE DATE,
E_DATE DATE
)
INSERT INTO TEST3 ( C_SET, C_ID, STTS, S_DATE, E_DATE ) VALUES (
'a2', '125', 'A', '01-JAN-2000', '15-MAR-2000');
INSERT INTO TEST3 ( C_SET, C_ID, STTS, S_DATE, E_DATE ) VALUES (
'a2', '125', 'B', '16-MAR-2000', '16-JUL-2000');
INSERT INTO TEST3 ( C_SET, C_ID, STTS, S_DATE, E_DATE ) VALUES (
'a2', '125', 'A', '17-JUL-2000', '01-JAN-3000');
INSERT INTO TEST3 ( C_SET, C_ID, STTS, S_DATE, E_DATE ) VALUES (
'a2', '889', 'B', '03-FEB-2000', '13-MAY-2000');
INSERT INTO TEST3 ( C_SET, C_ID, STTS, S_DATE, E_DATE ) VALUES (
'a2', '889', 'A', '14-MAY-2000', '01-JAN-3000');
COMMIT;
A simple select/group by of:
select c_set, stts, s_date, e_date, count(c_id)
from test3
group by c_set, stts, s_date, e_date
order by c_set, stts, s_date
gives (note date overlaps here, the crux of my problem):
c_set stts s_date e_date count(c_id)
a2 A 01-JAN-2000 15-MAR-2000 1
a2 A 14-MAY-2000 01-JAN-3000 1
a2 A 17-JUL-2000 01-JAN-3000 1
a2 B 03-FEB-2000 13-MAY-2000 1
a2 B 16-MAR-2000 16-JUL-2000 1
What I need is:
c_set stts s_date e_date count(c_id)
a2 A 01-JAN-2000 15-MAR-2000 1
a2 A 14-MAY-2000 16-JUL-2000 1
a2 A 17-JUL-2000 01-JAN-3000 2
a2 B 03-FEB-2000 15-MAR-2000 1
a2 B 16-MAR-2000 13-MAY-2000 2
a2 B 14-MAY-2000 16-JUL-2000 1
Geoff M |
|
| Back to top |
|
 |
Mark D Powell *nix forums Guru
Joined: 23 Apr 2005
Posts: 701
|
Posted: Fri Feb 18, 2005 1:38 pm Post subject:
Re: complex? SQL time series problem
|
|
|
Geoff, I suspect that you have not described the problem correctly.
The answer I gave should work for the problem as you described it.
Obviously neither I nor Daniel understand correctly what it is you need
to do.
HTH -- Mark D Powell -- |
|
| Back to top |
|
 |
Geoff M *nix forums beginner
Joined: 23 Feb 2005
Posts: 18
|
Posted: Thu Feb 17, 2005 9:08 pm Post subject:
Re: complex? SQL time series problem
|
|
|
In article <1108659136.624096@yasure>, damorgan@x.washington.edu says...
| Quote: | s_date e_date c_set c_id stts
01-jan-2000 15-mar-2000 a2 125 A
16-mar-2000 16-jul-2000 a2 125 B
17-jul-2000 sysdate a2 125 A
....
03-feb-2000 13-may-2000 a2 158 B
14-may-2000 sysdate a2 158 A
....
I need to group by c_set, stts and time interval, giving the count of
c_id, eg:
c-set stts s_date e_date count(c_id)
a2 A 01-jan-2000 15-mar-2000 1
a2 A 16-mar-2000 13-may-2000 0
a2 A 14-may-2000 16-jul-2000 1
a2 A 17-jul-2000 sysdate 2
a2 B 03-feb-2000 15-mar-2000 1
a2 B 16-mar-2000 13-may-2000 2
a2 B 14-may-2000 16-jul-2000 1
a2 B 17-jul-2000 sysdate 0
And exactly what is it about GROUP BY that won't work?
|
How do I get the e_date of 13-may-2000 in the stts=A group by?
Geoff M |
|
| Back to top |
|
 |
DA Morgan *nix forums Guru
Joined: 06 Mar 2005
Posts: 1042
|
Posted: Thu Feb 17, 2005 3:55 pm Post subject:
Re: complex? SQL time series problem
|
|
|
Geoff M wrote:
| Quote: | Hi all,
Oracle 9.2.0.6 on Linux ....
I have a table, a log over time of the status of clients in client sets
resembling the following:
s_date e_date c_set c_id stts
01-jan-2000 15-mar-2000 a2 125 A
16-mar-2000 16-jul-2000 a2 125 B
17-jul-2000 sysdate a2 125 A
....
03-feb-2000 13-may-2000 a2 158 B
14-may-2000 sysdate a2 158 A
....
I need to group by c_set, stts and time interval, giving the count of
c_id, eg:
c-set stts s_date e_date count(c_id)
a2 A 01-jan-2000 15-mar-2000 1
a2 A 16-mar-2000 13-may-2000 0
a2 A 14-may-2000 16-jul-2000 1
a2 A 17-jul-2000 sysdate 2
a2 B 03-feb-2000 15-mar-2000 1
a2 B 16-mar-2000 13-may-2000 2
a2 B 14-may-2000 16-jul-2000 1
a2 B 17-jul-2000 sysdate 0
Can anyone suggest a way this could be achieved in SQL without resorting
to PL/SQL, as I want if possible to create a materialized view of this
aggregation.
TIA
Geoff M
|
And exactly what is it about GROUP BY that won't work?
--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu
(replace 'x' with 'u' to respond) |
|
| Back to top |
|
 |
Geoff M *nix forums beginner
Joined: 23 Feb 2005
Posts: 18
|
Posted: Mon Feb 14, 2005 10:51 pm Post subject:
Re: complex? SQL time series problem
|
|
|
Mark.Powell@eds.com says...
| Quote: | Geoff, wouldn't that be just group by c_set, stts, (e_date - s_date)
with a matching select list plus count(*)?
|
Can't see it. More simply, I need to eventually plot this against a date
dimension, so I need:
s_date e_date c_set c_id stts
01-jan-2000 15-mar-2000 a2 125 A
17-jul-2000 sysdate a2 125 A
14-may-2000 sysdate a2 158 A
to become:
c-set stts s_date e_date count(c_id)
a2 A 01-jan-2000 15-mar-2000 1
a2 A 14-may-2000 16-jul-2000 1
a2 A 17-jul-2000 sysdate 2
Need to derive an e_date value of 16-jul-2000 amongst other things.
Geoff M |
|
| Back to top |
|
 |
Mark D Powell *nix forums Guru
Joined: 23 Apr 2005
Posts: 701
|
Posted: Mon Feb 14, 2005 1:20 pm Post subject:
Re: complex? SQL time series problem
|
|
|
Geoff, wouldn't that be just group by c_set, stts, (e_date - s_date)
with a matching select list plus count(*)?
HTH -- Mark D Powell -- |
|
| Back to top |
|
 |
Geoff M *nix forums beginner
Joined: 23 Feb 2005
Posts: 18
|
Posted: Mon Feb 14, 2005 1:47 am Post subject:
complex? SQL time series problem
|
|
|
Hi all,
Oracle 9.2.0.6 on Linux ....
I have a table, a log over time of the status of clients in client sets
resembling the following:
s_date e_date c_set c_id stts
01-jan-2000 15-mar-2000 a2 125 A
16-mar-2000 16-jul-2000 a2 125 B
17-jul-2000 sysdate a2 125 A
.....
03-feb-2000 13-may-2000 a2 158 B
14-may-2000 sysdate a2 158 A
.....
I need to group by c_set, stts and time interval, giving the count of
c_id, eg:
c-set stts s_date e_date count(c_id)
a2 A 01-jan-2000 15-mar-2000 1
a2 A 16-mar-2000 13-may-2000 0
a2 A 14-may-2000 16-jul-2000 1
a2 A 17-jul-2000 sysdate 2
a2 B 03-feb-2000 15-mar-2000 1
a2 B 16-mar-2000 13-may-2000 2
a2 B 14-may-2000 16-jul-2000 1
a2 B 17-jul-2000 sysdate 0
Can anyone suggest a way this could be achieved in SQL without resorting
to PL/SQL, as I want if possible to create a materialized view of this
aggregation.
TIA
Geoff M |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Thu Jan 08, 2009 3:49 am | All times are GMT
|
|
Debt Consolidation | Credit Cards | Bankruptcy | Hotels in Rome | Online Advertising
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|