pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Randolph Jones <jonesrf1@qwest.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: sort up then down
Date: Sun, 13 Apr 2003 19:01:34 -0400
Message-ID: <431.1050274894@sss.pgh.pa.us> (raw)
In-Reply-To: <3E98C24F.1070507@qwest.net>
References: <3E98C24F.1070507@qwest.net>

"Randolph Jones" <jonesrf1@qwest.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




view thread (2+ messages)

Message-ID: <431.1050274894@sss.pgh.pa.us>
Permalink:  ../431.1050274894@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/431.1050274894@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jonesrf1@qwest.net
  Subject: Re: sort up then down
  In-Reply-To: <431.1050274894@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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