Re: Show CAS, USD first; the left ordered by currency name

Lists: pgsql-sql
From: Emi Lu <emilu(at)encs(dot)concordia(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Subject: Show CAS, USD first; the left ordered by currency name
Date: 2009-07-30 19:51:39
Message-ID: 4A71F9CB.9050805@encs.concordia.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Good morning,

I have a currency table (code, description).

Example values:
ADF | Andorran Franc
... ...
ANG | NL Antillian Guilder
AON | Angolan New Kwanza
AUD | Australian Dollar
AWG | Aruban Florin
BBD | Barbados Dollar
USD | US Dollar
CAD | Canadian Dollar

Is there a way I can query to display USD AND CAD first, while other
rows are ordered by Code.

For example,

CAS | Canadian Dollar
USD | US Dollar
ADF | Andorran Franc
...

Thanks a lot!
--
Lu Ying


From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Show CAS, USD first; the left ordered by currency name
Date: 2009-07-30 20:05:29
Message-ID: 20090730200529.GA12697@tux
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Emi Lu <emilu(at)encs(dot)concordia(dot)ca> wrote:

> Good morning,
>
> I have a currency table (code, description).
>
> Example values:
> ADF | Andorran Franc
> ... ...
> ANG | NL Antillian Guilder
> AON | Angolan New Kwanza
> AUD | Australian Dollar
> AWG | Aruban Florin
> BBD | Barbados Dollar
> USD | US Dollar
> CAD | Canadian Dollar
>
> Is there a way I can query to display USD AND CAD first, while other
> rows are ordered by Code.
>
> For example,
>
> CAS | Canadian Dollar
> USD | US Dollar
> ADF | Andorran Franc
> ...
>

Sure:

test=*# select * from currency order by case when code='USD' then 0 when
code = 'CAD' then 1 end, code;
code | description
------+----------------------
USD | US Dollar
CAD | Canadian Dollar
ADF | Andorran Franc
ANG | NL Antillian Guilder
AON | Angolan New Kwanza
AUD | Australian Dollar
AWG | Aruban Florin
BBD | Barbados Dollar

Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°


From: sergey kapustin <kapustin(dot)sergey(at)gmail(dot)com>
To:
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Show CAS, USD first; the left ordered by currency name
Date: 2009-07-30 20:06:06
Message-ID: cf82f1380907301306yb51e3ecy387d40e915cd1c2c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

...order by currency not in('USD', 'AND', 'CAD');

this condition will be avaluated as FALSE for USD, AND and CAD, and as TRUE
for all other currencies. When the records are sorted the "false" are placed
on the top because false<true;.

On Thu, Jul 30, 2009 at 10:51 PM, Emi Lu <emilu(at)encs(dot)concordia(dot)ca> wrote:

> Good morning,
>
> I have a currency table (code, description).
>
> Example values:
> ADF | Andorran Franc
> ... ...
> ANG | NL Antillian Guilder
> AON | Angolan New Kwanza
> AUD | Australian Dollar
> AWG | Aruban Florin
> BBD | Barbados Dollar
> USD | US Dollar
> CAD | Canadian Dollar
>
> Is there a way I can query to display USD AND CAD first, while other rows
> are ordered by Code.
>
> For example,
>
> CAS | Canadian Dollar
> USD | US Dollar
> ADF | Andorran Franc
> ...
>
>
> Thanks a lot!
> --
> Lu Ying
>
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>


From: Harald Fuchs <hari(dot)fuchs(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Show CAS, USD first; the left ordered by currency name
Date: 2009-07-31 11:37:02
Message-ID: pu1vnxkrs1.fsf@srv.protecting.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

In article <4A71F9CB(dot)9050805(at)encs(dot)concordia(dot)ca>,
Emi Lu <emilu(at)encs(dot)concordia(dot)ca> writes:

> Good morning,
> I have a currency table (code, description).

> Example values:
> ADF | Andorran Franc
> ... ...
> ANG | NL Antillian Guilder
> AON | Angolan New Kwanza
> AUD | Australian Dollar
> AWG | Aruban Florin
> BBD | Barbados Dollar
> USD | US Dollar
> CAD | Canadian Dollar

> Is there a way I can query to display USD AND CAD first, while other
> rows are ordered by Code.

> For example,

> CAS | Canadian Dollar
> USD | US Dollar
> ADF | Andorran Franc
> ...

Probably the shortest solution is

SELECT code, description
FROM currency
ORDER BY code != 'CAD', code != 'USD', code;

BTW: your data are obsolete. Andorra has the Euro.


From: bricklen <bricklen(at)gmail(dot)com>
To: emilu(at)encs(dot)concordia(dot)ca
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Show CAS, USD first; the left ordered by currency name
Date: 2009-07-31 13:27:50
Message-ID: 33b743250907310627o637c1001v8e1a89060e053d76@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Alternatively,

...
ORDER BY (case when code in ('USD','CAD') then 0 else 1 end),code

On Fri, Jul 31, 2009 at 4:37 AM, Harald Fuchs<hari(dot)fuchs(at)gmail(dot)com> wrote:
> In article <4A71F9CB(dot)9050805(at)encs(dot)concordia(dot)ca>,
> Emi Lu <emilu(at)encs(dot)concordia(dot)ca> writes:
>
>> Good morning,
>> I have a currency table (code, description).
>
>> Example values:
>>  ADF | Andorran Franc
>>  ... ...
>>  ANG | NL Antillian Guilder
>>  AON | Angolan New Kwanza
>>  AUD | Australian Dollar
>>  AWG | Aruban Florin
>>  BBD | Barbados Dollar
>>  USD | US Dollar
>>  CAD | Canadian Dollar
>
>> Is there a way I can query to display USD AND CAD first, while other
>> rows are ordered by Code.
>
>> For example,
>
>> CAS | Canadian Dollar
>> USD | US Dollar
>> ADF | Andorran Franc
>> ...
>
> Probably the shortest solution is
>
>  SELECT code, description
>  FROM currency
>  ORDER BY code != 'CAD', code != 'USD', code;
>
> BTW: your data are obsolete.  Andorra has the Euro.
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>


From: Emi Lu <emilu(at)encs(dot)concordia(dot)ca>
To: sergey kapustin <kapustin(dot)sergey(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Show CAS, USD first; the left ordered by currency name
Date: 2009-07-31 14:05:49
Message-ID: 4A72FA3D.7090505@encs.concordia.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

"order by code not in ('USD', 'EUR', 'CAD') , code" is exactly what I
was looking for!

Good to know how "order by not in" works and thank you very much for all
your inputs!

--
Lu Ying

> ...order by currency not in('USD', 'AND', 'CAD');
>
> this condition will be avaluated as FALSE for USD, AND and CAD, and as
> TRUE for all other currencies. When the records are sorted the "false"
> are placed on the top because false<true;.
>
> On Thu, Jul 30, 2009 at 10:51 PM, Emi Lu <emilu(at)encs(dot)concordia(dot)ca
> <mailto:emilu(at)encs(dot)concordia(dot)ca>> wrote:
>
> Good morning,
>
> I have a currency table (code, description).
>
> Example values:
> ADF | Andorran Franc
> ... ...
> ANG | NL Antillian Guilder
> AON | Angolan New Kwanza
> AUD | Australian Dollar
> AWG | Aruban Florin
> BBD | Barbados Dollar
> USD | US Dollar
> CAD | Canadian Dollar
>
> Is there a way I can query to display USD AND CAD first, while other
> rows are ordered by Code.
>
> For example,
>
> CAS | Canadian Dollar
> USD | US Dollar
> ADF | Andorran Franc
> ...
>
>
> Thanks a lot!
> --
> Lu Ying
>
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org
> <mailto:pgsql-sql(at)postgresql(dot)org>)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>
>