pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
sort up then down 2+ messages / 2 participants [nested] [flat]
* sort up then down @ 2003-04-13 01:50 Randolph Jones <jonesrf1@qwest.net> 2003-04-13 23:01 ` Re: sort up then down Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 1 reply; 2+ messages in thread From: Randolph Jones @ 2003-04-13 01:50 UTC (permalink / raw) To: pgsql-sql 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; TIA rfjones ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: sort up then down 2003-04-13 01:50 sort up then down Randolph Jones <jonesrf1@qwest.net> @ 2003-04-13 23:01 ` Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 2+ messages in thread From: Tom Lane @ 2003-04-13 23:01 UTC (permalink / raw) To: Randolph Jones <jonesrf1@qwest.net>; +Cc: pgsql-sql "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 ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2003-04-13 23:01 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2003-04-13 01:50 sort up then down Randolph Jones <jonesrf1@qwest.net> 2003-04-13 23:01 ` Tom Lane <tgl@sss.pgh.pa.us>
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