From: Yudie <yudie@axiontech.com>
To: pgsql-sql@postgresql.org
Subject: How to re-sort a sorted query?
Date: Tue, 26 Oct 2004 14:23:30 -0500
Message-ID: <003001c4bb91$4c6647c0$a101a8c0@home.axiontech.com> (raw)
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
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: yudie@axiontech.com
Subject: Re: How to re-sort a sorted query?
In-Reply-To: <003001c4bb91$4c6647c0$a101a8c0@home.axiontech.com>
* 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