沒有問題啊。Create Table [table] (col1 Varchar(100)) Insert [table] Select 'A112' Union All Select 'B113' Union All Select 'D125' Union All Select 'C136' Union All Select 'A128' GO select * from [table] order By left(col1,1),right(col1,2) GO Drop Table [table] --Result /* col1 A112 A128 B113 C136 D125 */
....剛試了下,這句也沒問題 select * from titles order by left(title_id, 1), right(title_id, 1)
select * from maps_all where (1=1) order by cast(dbo.split(col1,2) as int), cast(dbo.split(col1 ,3) as int) 这是我实际的语句。
split 函数就是分割类似 A-111-11 的字符串。
如果col1 的值是这样的 A-12-156 A-265-1 A-8-25 回复人:paoluo(一天到晚游泳的鱼) ( 四星(高级)) 信誉:100 2007-07-19 14:38:12 得分:0 ? 沒有問題啊。Create Table [table] (col1 Varchar(100)) Insert [table] Select 'A112' Union All Select 'B113' Union All Select 'D125' Union All Select 'C136' Union All Select 'A128' GO select * from [table] order By left(col1,1),right(col1,2) GO Drop Table [table] --Result /* col1 A112 A128 B113 C136 D125 */
一樣沒問題的Create Table [table] (col1 Varchar(100)) Insert [table] Select 'A-12-156' Union All Select 'A-8-25' Union All Select 'A-8-27' GO select * from [table] order By left(col1,1),right(col1,2) GO Drop Table [table] --Result /* col1 A-8-25 A-8-27 A-12-156 */
select * from table order by left(col1,1),right(col1,2)
try Select 列出除了col12, col13外的所有列名 From(select *, cast(dbo.split(col1,2) as int) As col12, cast(dbo.split(col1 ,3) as int) As col13 from maps_all) A Order By col12, col13
这样不行,order by 后面不能固定 回复人:paoluo(一天到晚游泳的鱼) ( 四星(高级)) 信誉:100 2007-07-19 15:04:26 得分:0 ? 一樣沒問題的Create Table [table] (col1 Varchar(100)) Insert [table] Select 'A-12-156' Union All Select 'A-8-25' Union All Select 'A-8-27' GO select * from [table] order By left(col1,1),right(col1,2) GO Drop Table [table] --Result /* col1 A-8-25 A-8-27 A-12-156 */
order by後面的本來就是不確定的。另外,我這是舉例在普通的語句中是沒有問題的,但是order by中使用函數沒有測試,你試這個吧。Select 列出除了col12, col13外的所有列名 From(select *, cast(dbo.split(col1,2) as int) As col12, cast(dbo.split(col1 ,3) as int) As col13 from maps_all) A Order By col12, col13
谢谢,这个方法可行。 回复人:paoluo(一天到晚游泳的鱼) ( 四星(高级)) 信誉:100 2007-07-19 15:06:16 得分:0 ? try Select 列出除了col12, col13外的所有列名 From(select *, cast(dbo.split(col1,2) as int) As col12, cast(dbo.split(col1 ,3) as int) As col13 from maps_all) A Order By col12, col13
(col1 Varchar(100))
Insert [table] Select 'A112'
Union All Select 'B113'
Union All Select 'D125'
Union All Select 'C136'
Union All Select 'A128'
GO
select * from [table]
order By left(col1,1),right(col1,2)
GO
Drop Table [table]
--Result
/*
col1
A112
A128
B113
C136
D125
*/
order by --少了by
---------
應該不是這個原因,否則錯誤提示不是這樣的。
select * from titles
order by left(title_id, 1), right(title_id, 1)
A-12-156
A-265-1
A-8-25
回复人:paoluo(一天到晚游泳的鱼) ( 四星(高级)) 信誉:100 2007-07-19 14:38:12 得分:0
?
沒有問題啊。Create Table [table]
(col1 Varchar(100))
Insert [table] Select 'A112'
Union All Select 'B113'
Union All Select 'D125'
Union All Select 'C136'
Union All Select 'A128'
GO
select * from [table]
order By left(col1,1),right(col1,2)
GO
Drop Table [table]
--Result
/*
col1
A112
A128
B113
C136
D125
*/
(col1 Varchar(100))
Insert [table] Select 'A-12-156'
Union All Select 'A-8-25'
Union All Select 'A-8-27'
GO
select * from [table]
order By left(col1,1),right(col1,2)
GO
Drop Table [table]
--Result
/*
col1
A-8-25
A-8-27
A-12-156
*/
order by left(col1,1),right(col1,2)
Select 列出除了col12, col13外的所有列名
From(select *, cast(dbo.split(col1,2) as int) As col12, cast(dbo.split(col1 ,3) as int) As col13 from maps_all) A
Order By col12, col13
?
一樣沒問題的Create Table [table]
(col1 Varchar(100))
Insert [table] Select 'A-12-156'
Union All Select 'A-8-25'
Union All Select 'A-8-27'
GO
select * from [table]
order By left(col1,1),right(col1,2)
GO
Drop Table [table]
--Result
/*
col1
A-8-25
A-8-27
A-12-156
*/
From(select *, cast(dbo.split(col1,2) as int) As col12, cast(dbo.split(col1 ,3) as int) As col13 from maps_all) A
Order By col12, col13
回复人:paoluo(一天到晚游泳的鱼) ( 四星(高级)) 信誉:100 2007-07-19 15:06:16 得分:0
?
try
Select 列出除了col12, col13外的所有列名
From(select *, cast(dbo.split(col1,2) as int) As col12, cast(dbo.split(col1 ,3) as int) As col13 from maps_all) A
Order By col12, col13