Skip site navigation (1) Skip section navigation (2)

An order by question

From: David Arnold <darnold(at)northcoast(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: An order by question
Date: 2004-01-24 06:24:37
Message-ID: 3.0.5.32.20040123222437.009f3b60@mail.northcoast.com (view raw or flat)
Thread:
Lists: pgsql-sql
All,

I need a little help on a sorting problem. Imagine a table, call it
records, that has fields:

lastName
firstName
term

I want to sort the records by last name, then first name, and finally by
term. This almost does what I want:

select * from records order by lastName, firstName, term;

However, the possible values for term are:

2002F
2003S
2003X
2003F

Where F is for fall, S for spring, and X for summer session. Thus, a
straight alphabetical sort doesn't give me what I want. If the year is the
same, then I want a sort with S, then X, then F for identical year.

Any suggestions?


pgsql-sql by date

Next:From: Pragati KenkareDate: 2004-01-24 09:04:10
Subject: 'select nextval('seq_name');' in a function ?
Previous:From: A.BhuvaneswaranDate: 2004-01-24 05:11:35
Subject: Re: Fw: postgres logging

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group