Re: question about a select

From: Cindy <ctmoore(at)uci(dot)edu>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: question about a select
Date: 2003-10-09 21:42:44
Message-ID: 9118.1065735764@stephanus.tlg.uci.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Thanks for the speedy response!

Stephan Szabo writes:
>On Thu, 9 Oct 2003, Cindy wrote:
>
>
>> Text=# select distinct on (y_level) y_level, byteloc from
>> citations_by_level where aid=543 and wid=1 order by byteloc;
>> ERROR: SELECT DISTINCT ON expressions must match initial ORDER BY
>> expressions
>
>Maybe something like:
>
>select y_level from (select distinct on (y_level) y_level,
>byteloc from citations_by_level where aid=543 and wid=1) tab order by
>byteloc;

Hm...this seems to pick out the y_level with the largest byteloc
associated with it...I need the y_level with the smallest byteloc and
then sorted by that...lemme play this, but any other suggestions also
welcomed...

(EG, I got:
Text=# select y_level, byteloc from (select distinct on (y_level)
y_level, byteloc from citations_by_level where aid=543::smallint and
wid=1::smallint) tab order by byteloc;

y_level | byteloc
---------+---------
13 | 24017
11 | 36231
8 | 47240
10 | 96777
2 | 285678
5 | 400212
7,8 | 420879
...

but if you look at the raw data (or some of it):
---------+---------
1 | 29
1 | 84
2 | 423
3 | 827
4 | 1005
5 | 1169
6 | 1530
1 | 1698
2 | 1988
3 | 2284
4 | 2460
5 | 2638
6 | 2924
7 | 3155
8 | 3396
1 | 3673
2 | 4095
3 | 4387
4 | 4699
5 | 4944
6 | 5055
7 | 5406
8 | 5704
9 | 5996
10 | 6349
1 | 6578
2 | 7110

I want

1 | 29
2 | 423
3 | 827
4 | 1005
5 | 1169
6 | 1530
7 | 3155
8 | 3396
9 | 5996
10 | 6349

etc...

--
Cindy
ctmoore(at)uci(dot)edu

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Marc G. Fournier 2003-10-09 21:42:56 Re: Response from MySql AB (Re: Humor me: Postgresql vs.
Previous Message Karsten Hilbert 2003-10-09 21:33:08 Re: SQL query problem