我正在尝试对表格中的列进行排序,其中列中的值的格式为google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
);
,依此类推。
我尝试过查询
00000197-001-00001
值排序到select * from <table name> where <condition> order by column name.
。但在此之后,我得到的值是 00000197- 1000 -001 ,而不是 00000197- 100 -001
我得到的结果:
00000197-097-000001
00000197-098-000001
00000197-的 099 -000001
00000197-的 1000 -000001
00000197-的 100 -000001
00000197-1001-000001
00000197-1002-000001
00000197-1003-000001
00000197-1004-000001
00000197-1005-000001
00000197-1006-000001
00000197-1007-000001
00000197-1008-000001
00000197-1009-000001
00000197-的 1010 -000001
00000197-的 101 -000001
00000197-的 1011 -000001
00000197-1012-000001
预期结果:
00000197-097-000001
00000197-098-000001
00000197-的 099 -000001
00000197-的 100 -000001
00000197-101-000001
00000197-的 999 -000001
00000197-的 1000 -000001
00000197-1001-000001
00000197-1002-000001
00000197-1003-000001
请建议解决方案。 非常感谢提前。
答案 0 :(得分:1)
试试这个
SELECT *
FROM MyTable1
ORDER BY CAST(SUBSTRING(SUBSTRING(MyCol1, CHARINDEX('-', MyCol1, 0) + 1, 100), 0, CHARINDEX('-', substring(MyCol1, CHARINDEX('-', MyCol1, 0) + 1, 100), 0)) as int)
这适用于格式为X-Y-Z的任何长度的每个字符串。
答案 1 :(得分:0)
根据您的样本数据,您可以:
order by len(column1), column1
这个想法适用于任何数据库,但长度函数可能是length()
而不是len()
。