请问SQL语句应该怎么写?(50分)

  • 主题发起人 主题发起人 ayc_1999
  • 开始时间 开始时间
A

ayc_1999

Unregistered / Unconfirmed
GUEST, unregistred user!
请问以SQL语句怎么写:<br>序号<br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>怎么把序号用视图变为横向显示,如下:<br>1 &nbsp;2<br>3 &nbsp;4<br>5 &nbsp;6<br>7 &nbsp;8
 
你想做什么.
 
select (select 序号 from 表名 where MOD(序号, 2) = 1) as 奇数,<br>&nbsp; &nbsp; &nbsp; &nbsp;(select 序号 from 表名 where MOD(序号, 2) = 0) as 偶数<br>&nbsp; from dual
 
/*<br>需要借助临时表。<br>以下在SQL Server中测试通过。<br>*/<br>set nocount on<br>GO<br>create table &nbsp;sun(reco_no int)<br>GO<br>insert into sun(reco_no)<br>select 1<br>union all<br>select 2<br>union all<br>select 3<br>union all<br>select 4<br>union all<br>select 5<br>union all<br>select 6<br>union all<br>select 7<br>union all<br>select 8<br>union all &nbsp;--多写一行<br>select 9<br>GO<br>select * from sun<br>GO<br><br>select identity(int, 1, 1) ID, reco_no into #t1 from sun where reco_no % 2 = 1<br>GO<br>select * from #t1<br>GO<br>select identity(int, 1, 1) ID, reco_no into #t2 from sun where reco_no % 2 = 0<br>GO<br>select * from #t2<br>GO<br>select a.reco_no, b.reco_no<br>from #t1 a full join #t2 b<br>on a.id = b.id<br>GO<br>set nocount off<br>GO<br><br>//--------------以下是结果显示<br><br>reco_no &nbsp; &nbsp; <br>----------- <br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br><br>ID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;reco_no &nbsp; &nbsp; <br>----------- ----------- <br>1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1<br>2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3<br>3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 5<br>4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 7<br>5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 9<br><br>ID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;reco_no &nbsp; &nbsp; <br>----------- ----------- <br>1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2<br>2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4<br>3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 6<br>4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 8<br><br>reco_no &nbsp; &nbsp; reco_no &nbsp; &nbsp; <br>----------- ----------- <br>1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2<br>3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4<br>5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 6<br>7 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 8<br>9 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NULL
 

Similar threads

回复
0
查看
588
谦行
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
787
DelphiTeacher的专栏
D
D
回复
0
查看
645
DelphiTeacher的专栏
D
D
回复
0
查看
765
DelphiTeacher的专栏
D
后退
顶部