Re: Sorting Issue

From: Emi Lu <emilu(at)encs(dot)concordia(dot)ca>
To: "Ozer, Pam" <pozer(at)automotive(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Sorting Issue
Date: 2011-05-09 19:37:40
Message-ID: 4DC84284.4000903@encs.concordia.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> I have the following query
>
> Select VehicleTrimAbbreviated, VehicleTrimAbbreviatedId
>
> from VehicleTrimAbbreviated
>
> Where vehicleTrimAbbreviated like 'CX%'
>
> order by VehicleTrimAbbreviated asc
>
> Results:
>
> 532;"CX Hatchback"
>
> 536;"CXL Minivan"
>
> 3255;"CXL Premium Sedan"
>
> 537;"CXL Sedan"
>
> 538;"CXL Sport Utility"
>
> 3319;"CXL Turbo Sedan"
>
> 533;"CX Minivan"
>
> 1959;"CX Plus Minivan"
>
> 534;"CX Sedan"
>
> 535;"CX Sport Utility"
>
> 539;"CXS Sedan"
>
> Why would this not sort correctly? All the CX should be first, then CXL,
> Then CXS

Would you mind try:

Select VehicleTrimAbbreviated, VehicleTrimAbbreviatedId
from VehicleTrimAbbreviated
Where vehicleTrimAbbreviated like 'CX%'
order by

split_part(VehicleTrimAbbreviated, ' ', 1) asc,
split_part(VehicleTrimAbbreviated, ' ', 2) asc;

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Ozer, Pam 2011-05-09 19:39:00 Re: Sorting Issue
Previous Message Ozer, Pam 2011-05-09 16:25:16 Sorting Issue