pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedproblem with sql
4+ messages / 4 participants
[nested] [flat]
* problem with sql
@ 2002-06-01 00:32 Ricardo Javier Aranibar León <ricardo_jal@hotmail.com>
2002-06-01 10:35 ` Re: problem with sql D'Arcy J.M. Cain <darcy@druid.net>
0 siblings, 1 reply; 4+ messages in thread
From: Ricardo Javier Aranibar León @ 2002-06-01 00:32 UTC (permalink / raw)
To: pgsql-sql
Hi list,
I think that my head will exploit, I can't resolve this problem and I hope
that somebody can help me.
My data base stores the statistics of ping that are generated every minute.
For a day I have 1440 registers, I want to group them every 5 minutes.
I use this:
hb#select sum(tras), sum(lost), avg(min), avg(prom), avg(max) from simon
where fecha='2002-05-31' and ip='166.114.214.22' and hora between '00:00'
and '00:05';
This work for five register, but i like that this function as a bucle every
5 minutes for example in the next report the interval of hora between
'00:05' and '00:10' the next hora between '00:10' and '00:15'.....until
arrive hora between '23:55' and '24:00'
If somebody can help me I will thankfull
_________________________________________________________________
Descargue GRATUITAMENTE MSN Explorer en
http://explorer.yupimsn.com/intl.asp.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: problem with sql
2002-06-01 00:32 problem with sql Ricardo Javier Aranibar León <ricardo_jal@hotmail.com>
@ 2002-06-01 10:35 ` D'Arcy J.M. Cain <darcy@druid.net>
0 siblings, 0 replies; 4+ messages in thread
From: D'Arcy J.M. Cain @ 2002-06-01 10:35 UTC (permalink / raw)
To: Ricardo Javier Aranibar León <ricardo_jal@hotmail.com>; +Cc: pgsql-sql
On May 31, 2002 08:32 pm, Ricardo Javier Aranibar León wrote:
> I think that my head will exploit, I can't resolve this problem and I hope
> that somebody can help me.
Can't have that. It might leave a mess in our nice, clean mailing list. :-)
> My data base stores the statistics of ping that are generated every minute.
> For a day I have 1440 registers, I want to group them every 5 minutes.
> I use this:
> hb#select sum(tras), sum(lost), avg(min), avg(prom), avg(max) from simon
> where fecha='2002-05-31' and ip='166.114.214.22' and hora between '00:00'
> and '00:05';
>
> This work for five register, but i like that this function as a bucle every
> 5 minutes for example in the next report the interval of hora between
> '00:05' and '00:10' the next hora between '00:10' and '00:15'.....until
> arrive hora between '23:55' and '24:00'
Well, how accurate does this have to be? Are you just trying to see some
statisticle correlations or do you need to actually count each bing once and
only once for some sort of accounting purposes. I assume the former in which
case the following may be what you are looking for..
...where hora between 'NOW'::timestamp - '5 MINUTE'::interval and 'NOW.
--
D'Arcy J.M. Cain <darcy@{druid|vex}.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
^ permalink raw reply [nested|flat] 4+ messages in thread
* problem with sql
@ 2003-10-19 16:56 Adaś <adamn@qwe.pl>
2003-10-25 11:06 ` Re: problem with sql Michael Glaesmann <grzm@myrealbox.com>
0 siblings, 1 reply; 4+ messages in thread
From: Adaś @ 2003-10-19 16:56 UTC (permalink / raw)
To: pgsql-sql
Hello to everyone,
In my own database, I linked customers table with orders table using
one-to-many relation. I need to check status of last order for each
customer and then set customer's status. I made a query using LAST and
GROUP BY to select last order for each customer and I wanted to use it
in UPDATE query, but it seems to be impossible. Is here anybody who
knows how to solve this problem? (I work with MS Access).
Adam
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: problem with sql
2003-10-19 16:56 problem with sql Adaś <adamn@qwe.pl>
@ 2003-10-25 11:06 ` Michael Glaesmann <grzm@myrealbox.com>
0 siblings, 0 replies; 4+ messages in thread
From: Michael Glaesmann @ 2003-10-25 11:06 UTC (permalink / raw)
To: pgsql-sql
Hi Adam,
On Monday, Oct 20, 2003, at 01:56 Asia/Tokyo, Adaś wrote:
> status. I made a query using LAST and GROUP BY to select last order
> for each customer and I wanted to use it in UPDATE query, but it seems
> to be impossible.
I don't believe PostgreSQL has a built-in function similar to MS
Access' LAST. Something like the following might work for you:
SELECT DISTINCT ON (client) client, order_number, order_date FROM
orders ORDER BY order_date desc
You might have to change the DISTINCT ON terms to match what you want.
Check the docs for usage of DISTINCT ON.
Also, I've heard it's quite easy to write a custom function to do what
you want using CREATE FUNCTION. Haven't done it myself.
Hope it helps.
Michael
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2003-10-25 11:06 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-06-01 00:32 problem with sql Ricardo Javier Aranibar León <ricardo_jal@hotmail.com>
2002-06-01 10:35 ` D'Arcy J.M. Cain <darcy@druid.net>
2003-10-19 16:56 problem with sql Adaś <adamn@qwe.pl>
2003-10-25 11:06 ` Michael Glaesmann <grzm@myrealbox.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox