试试这个问题,
select *
from myStringSorting
order by Cast(Replace(Substring(mycol,0,CHARINDEX('-',mycol)),'WP','') as Int) asc
,Cast(Replace(Substring(mycol,CHARINDEX('-',mycol) + 1,LEN(mycol)),'WP','') as Int) asc
看看这个链接,http://sqlfiddle.com/#!3/ca45f/5
用DISTINCT,
With CTE as
(
select distinct mycol
from myStringSorting
)
select * from CTE
order by Cast(Replace(Substring(mycol,0,CHARINDEX('-',mycol)),'WP','') as Int) asc
,Cast(Replace(Substring(mycol,CHARINDEX('-',mycol) + 1,LEN(mycol)),'WP','') as Int) asc
用DISTINCT,没有CTE,使用sub查询,
Select a.mycol from
(
select distinct mycol
from myStringSorting
)as a
order by Cast(Replace(Substring(a.mycol,0,CHARINDEX('-',a.mycol)),'WP','') as Int) asc
,Cast(Replace(Substring(a.mycol,CHARINDEX('-',a.mycol) + 1,LEN(a.mycol)),'WP','') as Int) asc
@juergen d谢谢,我是这样做的:) –
这是你的数据库的中间? SQL Server,MySql,Oracle等。 – TechDo
MySQL根据000webhost的网站 –