| From: | Bruno Wolff III <bruno(at)wolff(dot)to> |
|---|---|
| To: | Lane Van Ingen <lvaningen(at)esncc(dot)com> |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: SQL Newbie |
| Date: | 2005-08-12 18:04:55 |
| Message-ID: | 20050812180455.GA32286@wolff.to |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
> Data in speed history looks like this:
> interface_id updated_time speed
> 1 2005-08-11 08:10:23 450112
> 1 2005-08-11 10:53:34 501120 <---
> 1 2005-08-11 10:58:11 450112
> 2 2005-08-11 08:10:23 450112 <---
> 2 2005-08-11 11:00:44 350234
> 3 2005-08-11 08:10:23 450112 <---
> The rows of speed_history I want back are marked above with ' <--- '.
>
> Query results should look like:
> interface.interface_id
> interface.link_description
> speed_history.updated_time
> speed_history.speed
The main idea is to join a select of max speeds grouped by interface_id
to the interface table.
If the query runs too slow, then you may get better performance having an
index on (interface_id, speed) and using subselects. In this case
you want to select information about all of interfaces and then have
one of the columns be a subselect that selects one (using limit) speed
from rows that have a matching interface_id ordered by interface_id desc,
speed desc. This combination of limit and order by will be faster than
using max.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Owen Jacobson | 2005-08-12 18:05:26 | Re: SQL Newbie |
| Previous Message | Nick Stone | 2005-08-12 17:57:34 | Re: SQL Newbie |