我有一个包含
的varchar列0.1
0.8
0.2
Drr
0.11
0.8.1
0.8.2
0.2.1
如何对其进行排序以获得这样的结果?
0.1
0.2
0.2.1
0.8
0.8.1
0.8.2
0.11
Drr
由于
答案 0 :(得分:1)
你可以试试这个:
WITH isContainAlpha AS
(
SELECT *,
CASE WHEN version_no LIKE '%[a-z]%' THEN 1 ELSE 0 END AS withAlpha,
CASE WHEN version_no LIKE '%[a-z]%' THEN '0' ELSE version_no END AS version_no_rewrite
FROM tableOne
)
SELECT version_no
FROM isContainAlpha
ORDER BY withAlpha, CAST('/'+REPLACE(version_no_rewrite,'.','/')+'/' as hierarchyID)