简体   繁体   中英

sql sorting a column with numbers and words

I'm having issues sorting a column of numbers and words a specific Ascending order of type nvarchar .

when I run this query

select GradedDescriptions from cards order by GradedDescriptions asc

I get

10
5
8
8.5
Authentic
Authentic
Black 10

But my desired result is

Authentic
5
8
8.5
10
Black 10

Is there a way to put Authentic before the numbers and Black 10 at the end?

Perhaps something like this

Declare @YourTable Table ([GradedDescriptions] varchar(50))
Insert Into @YourTable Values 
 ('10')
,('5')
,('8')
,('8.5')
,('Authentic')
,('Black 10')
 
Select * from @YourTable 
Order by try_convert(money,right([GradedDescriptions],3))
        ,[GradedDescriptions]

Results

GradedDescriptions
Authentic
5
8
8.5
10
Black 10

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM