找回密码
 注册账号

QQ登录

只需一步,快速开始

手机号码,快捷登录

手机号码,快捷登录

初学者课程:T3自学|T6自学|U8自学软件下载课件下载工具下载资料:通资料|U8资料|NC|培训|年结积分规则 | 使用常见问题Q&A
知识库:U8 | | NC | U9 | OA | 政务U8|U9|NCC|NC65|NC65客开|NCC客开新手必读 | 任务 | 快速增金币用友QQ群[微信群]
查看: 3777|回复: 2

[技巧] 【精】行列互换通用存储过程

[复制链接]
发表于 2012-8-17 22:30:22 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册账号

×
本帖最后由 windy8848 于 2012-8-17 22:34 编辑

--创建测试数据
create table TestData(姓名 varchar(10), 语文 dec(14,2), 数学 dec(14,2), 英语 dec(14,2), 物理 dec(14,2), 化学 dec(14,2))
insert TestData
select '张三',cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2))
union all
select '李四',cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2))
union all
select '王五',cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2))
union all
select '赵六',cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2))
union all
select '陈七',cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2))
union all
select '孙八',cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2))
union all
select '刘二',cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2)),cast(RAND()*100 AS dec(14,2))

SELECT * FROM TestData
姓名 语文 数学 英语 物理 化学
张三 75.29 81.49 80.96 46.59 5.38
李四 66.20 98.39 10.37 6.96 79.53
王五 22.40 53.79 19.02 85.18 43.37
赵六 77.53 67.82 57.42 39.98 44.37
陈七 9.96 55.43 3.71 80.10 56.30
孙八 50.98 7.03 23.16 95.61 12.28
刘二 45.64 10.48 30.66 48.60 13.68

--测试转换结果
proc_hanglie 'TestData','姓名','科目'

行列转换通用存储过程下载 行列互换通用存储过程.rar (795 Bytes, 下载次数: 5, 售价: 10 金币) 充值金币->

科目 张三 李四 王五 赵六 陈七 孙八 刘二
语文 60.18 67.88 41.37 87.81 31.68 93.19 7.49
数学 4.84 80.32 45.46 59.11 44.10 99.18 0.98
英语 71.65 70.90 81.85 31.19 74.37 39.56 32.34
物理 92.32 41.68 15.45 56.33 75.35 17.50 19.95
化学 66.42 49.00 36.14 11.65 5.62 1.18 61.61

DROP TABLE TestData




发表于 2012-8-26 09:08:59 | 显示全部楼层
应该是过程很好用
回复 点赞 拍砖

使用道具 举报

发表于 2013-12-4 17:07:23 | 显示全部楼层
这个查询真好呀
回复 点赞 拍砖

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号

本版积分规则

QQ|站长微信|Archiver|手机版|小黑屋|用友之家 ( 蜀ICP备07505338号|51072502110008 )

GMT+8, 2024-12-4 01:37 , Processed in 0.064855 second(s), 13 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表