易截截图软件、单文件、免安装、纯绿色、仅160KB

我想用一条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


相关文档:

SQL Server:将列更新从一个表传递到另一个表

问:怎样在一个UPDATE语句中使用表B的三个列更新表A中的三个列?
  答:对这个问题,您可以使用强大的关系代数。本页中的代码说明了如何组合使用from子句和JOIN操作,以达到用其他表中数据更新指定列的目的。在设计关系表达式时,您需要决定是否需要单一行匹配多个行(一对多关系),或者需要多个行匹配被联接表中的单一 ......

Oracle数据库SQL*plus常用的命令和函数

 
Oracle中常用的命令和函数,做个整理,以备以后用到,方便查阅。
 
常用命令:
 
连接sqlplus
 
命令行下运行cmd进入,如以sys模式登陆,命令如下:
 
(1).sqlplus "sys/zhb126 as sysdba"
 
(2).sqlplus/nolog connect sys/zhb126 as sysdba
 
(3).sqlplus scott ......

SQL Server Express的使用

      今天终于知道SQL 2005 怎么用了,感觉以前太懒了,明明想知道的东西可是因为已经有sql2000就懒得查。知识这东西是日积月累的,真正到用的时候才去补就已经晚了。
      以前安装VS2005的时候就看到安装完了以后会有一个SQL2005,可是自己不会用,那个时候只 ......

通过T SQL语句压缩SQL Server数据库

清空日志:
dump transaction 库名 with no_log
截断日志:
backup log 库名 with no_log
压缩数据库:
dbcc shrinkdatabase (库名, 目标比率)
压缩数据库文件:
dbcc shrinkfile (文件名或ID, 目标大小)
文件名或ID可以通过系统表sysfiles查找,如果不指定目标大小SQL Server将最大限度的压缩数据库文件。
查看压 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号