Re: Sorting Issue
От | Samuel Gendler |
---|---|
Тема | Re: Sorting Issue |
Дата | |
Msg-id | BANLkTikJhPpiM-rV9DX1rp_1dJhbTGOtZQ@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Sorting Issue (Emi Lu <emilu@encs.concordia.ca>) |
Ответы |
Re: Sorting Issue
|
Список | pgsql-sql |
On Mon, May 9, 2011 at 1:38 PM, Emi Lu <emilu@encs.concordia.ca> wrote:
Hi Pam,This query works, right?
>> Select VehicleTrimAbbreviated, VehicleTrimAbbreviatedId
>> from VehicleTrimAbbreviated
>> Where vehicleTrimAbbreviated like 'CX%'
>> order by
>>
>> split_part(VehicleTrimAbbreviated, ' ', 1) asc,
>> split_part(VehicleTrimAbbreviated, ' ', 2) asc;
Reason:
======
. split_part(VehicleTrimAbbreviated, ' ', 1) return the string before the blank
. split_part(VehicleTrimAbbreviated, ' ', 1) return the string after the blank
So
[1] you order by CX, CXL, CXS first
[2] you order by second part "Hatchback, Minivan... "
Is there clear now?
Not really. It should sort alphabetically the same in either case. Here's an alphabetic sort of similar strings in python
>>> a = ["CX Hatchback", "CXL Minivan", "CXL Premium Sedan", "CXL Sedan", "CXL Sport Utility", "CXL Turbo Sedan", "CX Minivan", "CXS Sedan"]
>>> a.sort()
>>> a
['CX Hatchback', 'CX Minivan', 'CXL Minivan', 'CXL Premium Sedan', 'CXL Sedan', 'CXL Sport Utility', 'CXL Turbo Sedan', 'CXS Sedan']
It's not at all clear why they are not coming out of the db in alphabetically sorted order when the query includes "order by VehicleTrimAbbreviated asc"
В списке pgsql-sql по дате отправления: