日期:2014-05-19  浏览次数:20667 次

一个相当困扰的问题
请问
在数据库中有这么一个表
有一列是
a
a
b
b
c
c
如何用sql语句让它按以下现实
a
b
c
a
b
c

------解决方案--------------------
declare @t table(a varchar(10))
insert into @t
select 'a '
union all select 'a '
union all select 'b '
union all select 'b '
union all select 'c '
union all select 'c '

select distinct a from @t
union all
select distinct a from @t
/*
(所影响的行数为 6 行)

a
----------
a
b
c
a
b
c
*/
------解决方案--------------------

create table t(c varchar(10))
insert t
select 'a '
union all select 'a '
union all select 'b '
union all select 'b '
union all select 'c '
union all select 'c '


select c1=identity(int,1,1),* into #lsb from t

select *,c1%2
from #lsb
order by c1%2 desc,c1 asc


drop table t,#lsb