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

How to re-sort a sorted query?

From: "Yudie" <yudie(at)axiontech(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: How to re-sort a sorted query?
Date: 2004-10-26 19:23:30
Message-ID: 003001c4bb91$4c6647c0$a101a8c0@home.axiontech.com (view raw or flat)
Thread:
Lists: pgsql-sql
I have a query that need to be sorted in order of price of store's product with unique store number.

Here is a sample data of storeproduct table:


ItemSku , StoreNumber , Price
==========================
10001 , 7 , 30.00
10001 , 7 , 35.00 <-- duplicate store number 
10001 , 5 , 45.00
10001 , 2 , 50.00

Then I do this query to get unique store number and also the cheapest price from each store:

SQL= "Select distinct on (storenumber), itemsku, storenumber,price
from storeproduct where itemsku='10001' 
order by storenumber, price"

Result #1:
ItemSku , StoreNumber , Price
10001 , 2 , 50.00
10001 , 5 , 45.00
10001 , 7 , 30.00

The question is how to make the query that returns as above but sorted by price?


Thanks..
Yudie

Responses

pgsql-sql by date

Next:From: Wei WengDate: 2004-10-26 20:23:20
Subject: How do you compare (NULL) and (non-NULL)?
Previous:From: Jeff BoesDate: 2004-10-26 17:00:01
Subject: How to recognize trigger-inserted rows?

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