我正在尝试排列具有以下值的列:
6-3
11-1
3
8-5
5
6-2
1
7
11-4
8-12
2
我希望它们像这样排列:
1
2
3
5
7
6-2
6-3
8-5
8-12
11-1
11-4
我现在有这个查询:
select column_name from database_name.dbo.table_name
order by
(case when (BOX_NO not like '%-%')
then -1 when (BOX_NO like '%-%')
then cast(SUBSTRING(reverse(BOX_NO), LEN(BOX_NO)-(CHARINDEX('-', reverse(BOX_NO))-2), 0) as int) end),
(case when (column_name not like '%-%')
then cast(column_name as int)
when (column_name like '%-%')
then cast(SUBSTRING(column_name, LEN(column_name)-(CHARINDEX('-', reverse(column_name))-2), 8000) as int) end)
我要疯了。如果有人可以帮助我,那就太好了。谢谢!