我想用一条SQL显示这样的结果
不知道这样的要求能不能实现?
比如我有一张表T1,里面只有一个字段1
里面有100条记录,如下所示:
字段1
A1
A2
A3
A4
...
A100
我想用一条SQL显示这样的结果
第一列 第二列 ... 第十列
A1 A11 A91
A2 A12 A92
A3 A13 A93
... ... ...
A10 A20 A100
不知可否实现?当然,也不一定分成十列,可能是五列等等,请高手赐教。谢谢
--假设字段不存在相同值.
select
max(case (px - 1) % 10 when 0 then 字段1 else '' end) [c1],
max(case (px - 1) % 10 when 1 then 字段1 else '' end) [c2],
max(case (px - 1) % 10 when 2 then 字段1 else '' end) [c3],
max(case (px - 1) % 10 when 3 then 字段1 else '' end) [c4],
max(case (px - 1) % 10 when 4 then 字段1 else '' end) [c5],
max(case (px - 1) % 10 when 5 then 字段1 else '' end) [c6],
max(case (px - 1) % 10 when 6 then 字段1 else '' end) [c7],
max(case (px - 1) % 10 when 7 then 字段1 else '' end) [c8],
max(case (px - 1) % 10 when 8 then 字段1 else '' end) [c9],
max(case (px - 1) % 10 when 9 then 字段1 else '' end) [c10]
from
(
select * , px = (select count(1) from t1 where 字段1 < t.字段1) + 1 from t1 t
) m
group by (px - 1) / 10
--如果字段存在相同值.
--sql 2000需要使用临时表
select * , px = identity(int,1,1) into tmp from t1
select
max(case (px - 1) % 10 when 0 then 字段1 else '' end) [c1],
max(case (px - 1) % 10 when 1 then 字段1 else '' end) [c2],
max(case (px - 1) % 10 when 2 then 字段1 else '' end) [c3],
m
相关文档:
Oracle中常用的命令和函数,做个整理,以备以后用到,方便查阅。
常用命令:
连接sqlplus
命令行下运行cmd进入,如以sys模式登陆,命令如下:
(1).sqlplus "sys/zhb126 as sysdba"
(2).sqlplus/nolog connect sys/zhb126 as sysdba
(3).sqlplus scott ......
SQL SERVER DBCC命令解释
八点钟起床一直搞到现在,好多还不太记得,先放上来以后慢慢修改
2007-05-01 12:56:28
---------------------
--1 dbcc trraceon DBCC TRACEOFF
--对于数据库死锁,通常可以通过TRACE FLAG 1204、1205、1206,检查ERRORLOG里面的输出,和分析SQLTRACE的执行上下文判断死锁问题的来由。
--T ......
今天终于知道SQL 2005 怎么用了,感觉以前太懒了,明明想知道的东西可是因为已经有sql2000就懒得查。知识这东西是日积月累的,真正到用的时候才去补就已经晚了。
以前安装VS2005的时候就看到安装完了以后会有一个SQL2005,可是自己不会用,那个时候只 ......
Oracle SQL性能优化技巧大总结 收藏
(1)选择最有效率的表名顺序(只在基于规则的优化器中有效):
Oracle的解析器按照从右到左的顺序处理from子句中的表名,from子句中写在最后的表(基础表 driving table)将被最先处理,在from子句中包含多个表的情况下,你必须选择记录条数最少的表作为基础表。如果有3个以 ......