Re: sort up then down

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Randolph Jones" <jonesrf1(at)qwest(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: sort up then down
Date: 2003-04-13 23:01:34
Message-ID: 431.1050274894@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Randolph Jones" <jonesrf1(at)qwest(dot)net> writes:
> I have database fields 1234567891.001;
> I want to sort on first 10 digits descending; (last date first)
> then ascending on the last 3 digit (page numbers)
> the statement below gives the right answer,
> but is this how to do it?

> SELECT substr(imgname,1,10) AS name, substring(imgname,12,3) AS pg FROM
> fax GROUP BY imgname, pg ORDER BY name DESC, pg ASC;

The ORDER BY seems fine. I think the GROUP BY is redundant: if you're
grouping by imgname, there's no effect to grouping by pg as well, no?

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Yudha Setiawan 2003-04-14 01:36:48 How Do I Hide Trigger ??
Previous Message Daniel Seichter 2003-04-13 20:05:00 SELECT Blobs into a delphi program