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

ORDER BY Clause

From: Derrick Betts <list(at)blueaxis(dot)com>
To: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: ORDER BY Clause
Date: 2008-04-13 02:52:38
Message-ID: 48017576.6070607@blueaxis.com (view raw or flat)
Thread:
Lists: pgsql-novice
I have a query: SELECT fruit, group_number, ordering_number FROM 
fruit_groups ORDER BY group_number, order_number;

The results look like:
    fruit   |   group_number   |   ordering_number
--------+------------------+-------------------
 cherry  |              1             |              1
 orange |              1             |              2
   apple |              2             |              1
     pear |              2             |              2
 banana |              3             |              1
     kiwi |               3            |              2


I would like the results to look like:
    fruit   |   group_number   |   ordering_number
--------+------------------+-------------------
   apple |              2             |              1
 orange |              2             |              2
 banana |              3             |              1
     kiwi |               3            |              2
 cherry  |              1             |              1
 orange |              1             |               2

I want the group_number to be grouped together, then sorted by the 
ordering_number, then listed in the output alphabetically by the fruit 
name listed first in the group_number (as defined by the ordering_number).

Does anyone know how I might modify my statement to get this ordering?
Thanks,
Derrick


Responses

pgsql-novice by date

Next:From: Frank BaxDate: 2008-04-13 04:06:01
Subject: Re: ORDER BY Clause
Previous:From: Jaisen N.D.Date: 2008-04-12 05:21:45
Subject: problem with 8.1: createdb: could not connect to database postgres: could not connect to server: No such file or directory

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