惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
Vercel News
Vercel News
Recent Announcements
Recent Announcements
B
Blog RSS Feed
Y
Y Combinator Blog
M
MIT News - Artificial intelligence
MongoDB | Blog
MongoDB | Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
D
Docker
Jina AI
Jina AI
IT之家
IT之家
人人都是产品经理
人人都是产品经理
L
LangChain Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
博客园 - 叶小钗
The GitHub Blog
The GitHub Blog
The Cloudflare Blog
A
About on SuperTechFans
Hugging Face - Blog
Hugging Face - Blog

博客园 - CODE

jquery 加载 - CODE - 博客园 jquery ajxj - CODE - 博客园 页面复合表头的做法 - CODE - 博客园 自动产生树,并建立树结构 - CODE - 博客园 HTML 自动产生Radio分组 - CODE - 博客园 获取Table当前单元格的值 - CODE - 博客园 (转)优化数据库的思想及sql语句优化的原则 软件孵化室自助基金成立仪式 转: 移动客户端系统升级思路 转:调用Windows Mobile自带的控制面板项 程序员的基本素质 BCP的应用 VC++ 6.0访问Sql Server 协会的篮球比赛 软件协会05级高级会员离校仪式--发言稿 软输入面板 软件孵化室为筹集“静·挚”基金倡议书 微软的Webcasts系列讲座 http://www.cnblogs.com/upto/archive/2006/04/10/CompressWebService.html(收集)
sql server 行变成列的DEMO
CODE · 2009-11-02 · via 博客园 - CODE

create table A
(
 属性ID int,
 年份 int
)

delete a
select * From  A

insert  A
select 1, 2008
insert  A
select 2, 2009

create table B
(
 年份 int,
 月份 int,
    金额 int

)
insert B
select 2008,1,20
insert B
select 2008,2,30
insert B
select 2008,3,40
insert B
select 2008,4,10
insert B
select 2009,1,60
insert B
select 2009,2,25
insert B
select 2009,3,5
insert B
select 2009,4,10


select
  A.属性ID,
  A.年份,
   max(case when (A.年份=B.年份) and (B.月份=1) then B.金额 END) as '一月',
 max(case when (A.年份=B.年份) and (B.月份=2) then B.金额 END) as '二月',
 max(case when (A.年份=B.年份) and (B.月份=3) then B.金额 END) as '三月',
 max(case when (A.年份=B.年份) and (B.月份=4) then B.金额 END) as '四月'
From A
  inner join B on A.年份 = B.年份
group by A.属性ID,A.年份

1 2008 20 30 40 10
2 2009 60 NULL 5 10