create table a (id varchar(10))insert into a select '2006-5-25' union all select '2006-12-2' union all select '2006-12-2' union all select '2005-6-1' union all select '2005-6-1' union all select '2005-3' union all select '2001-3' union all select '2000-6-1' union all select '2000-1-1' union all select '1985-5'select * from a order by cast (id+(case when len(id)>7 then '' else '-01' end ) as datetime )id ---------- 1985-5 2000-1-1 2000-6-1 2001-3 2005-3 2005-6-1 2005-6-1 2006-5-25 2006-12-2 2006-12-2(所影响的行数为 10 行)
order by date desc
不知道lz是不是这个意思
2006-5-25
2006-12-2
2006-12-2
2005-6-1
2005-6-1
2005-3
2001-3
2000-6-1
2000-1-1
1985-5
union all select '2006-12-2'
union all select '2006-12-2'
union all select '2005-6-1'
union all select '2005-6-1'
union all select '2005-3'
union all select '2001-3'
union all select '2000-6-1'
union all select '2000-1-1'
union all select '1985-5'select * from a
order by cast (id+(case when len(id)>7 then '' else '-01' end ) as datetime )id
----------
1985-5
2000-1-1
2000-6-1
2001-3
2005-3
2005-6-1
2005-6-1
2006-5-25
2006-12-2
2006-12-2(所影响的行数为 10 行)