SQL Server数据库动态交叉表的参考示例
来源:互联网 发布:js style.left无效 编辑:程序博客网 时间:2024/05/16 14:32
SQL Server数据库动态交叉表的参考示例:
--建立测试环境
以下为引用的内容:
set nocount on
create table test(model varchar(20),date int ,qty int)
insert into test select 'a','8','10'
insert into test select 'a','10','50'
insert into test select 'b','8','100'
insert into test select 'b','9','200'
insert into test select 'b','10','100'
insert into test select 'c','10','200'
insert into test select 'd','10','300'
insert into test select 'e','11','250'
insert into test select 'e','12','100'
insert into test select 'f','12','150'
go
--测试
declare @sql varchar(8000)
set @sql='select model,'
select @sql=@sql+'sum(case when
date='''+cast(date as varchar(10))+''' then qty else 0 end)
['+cast(date as varchar(10))+'],'
from (select distinct top 100 percent date
from test order by date)a
set @sql =left(@sql,len(@sql)-1)+' from test group by model'
exec(@sql)
--删除测试环境
drop table test
set nocount off
/**//*
model 8 9 10 11 12
-------------------- ----------- ----------- ----------- ----------- -----------
a 10 0 50 0 0
b 100 200 100 0 0
c 0 0 200 0 0
d 0 0 300 0 0
e 0 0 0 250 100
f 0 0 0 0 150
*/
- SQL Server数据库动态交叉表的参考示例
- Sql Server 2008的动态交叉表
- SQL SERVER数据库全文索引的示例
- SQL SERVER数据库全文索引的示例
- SQL server 交叉表
- SQL动态交叉表
- SQL动态交叉表
- Sql Server交叉表的用法
- 一个完整的SQL SERVER数据库全文索引的示例
- 一个完整的SQL SERVER数据库全文索引的示例
- 一个完整的SQL SERVER数据库全文索引的示例
- 一个完整的SQL SERVER数据库全文索引的示例
- 一个完整的SQL SERVER数据库全文索引的示例
- 一个完整的SQL SERVER数据库全文索引的示例
- 一个完整的SQL SERVER数据库全文索引的示例
- 一个完整的SQL SERVER数据库全文索引的示例
- 一个完整的SQL SERVER数据库全文索引的示例
- 一个完整的SQL SERVER数据库全文索引的示例
- 枚举:Key与ModifierKeys
- PHP+MySQL应用的乱码根绝方案
- gridview中的自定义删除按钮的 CommandName不要等于“delete”。
- FusionMaps的使用(一)
- PC的启动
- SQL Server数据库动态交叉表的参考示例
- 分页技术pager-taglib.jar struts2 啊啊
- 备忘:《观止:微软创建NT和未来的夺命狂奔》
- pkg高级用法权限信息
- 23种设计模式
- GDB文档
- java 读取cmd总结
- 关于 CGI 的安全性
- JQuery ajax参数表