首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

一个相当困扰的有关问题

2012-01-16 
一个相当困扰的问题请问在数据库中有这么一个表有一列是aabbcc如何用sql语句让它按以下现实abcabc[解决办

一个相当困扰的问题
请问
在数据库中有这么一个表
有一列是
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

热点排行