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

推荐订阅源

I
Intezer
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
AWS News Blog
AWS News Blog
G
GRAHAM CLULEY
P
Privacy & Cybersecurity Law Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cybersecurity and Infrastructure Security Agency CISA
N
News | PayPal Newsroom
T
Tenable Blog
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Secure Thoughts
P
Privacy International News Feed
IT之家
IT之家
Project Zero
Project Zero
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
博客园_首页
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
Martin Fowler
Martin Fowler
NISL@THU
NISL@THU
I
InfoQ
D
DataBreaches.Net
有赞技术团队
有赞技术团队
K
Kaspersky official blog
Security Latest
Security Latest
The Register - Security
The Register - Security
Hugging Face - Blog
Hugging Face - Blog
S
Security @ Cisco Blogs
P
Proofpoint News Feed
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
AI
AI
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
N
News and Events Feed by Topic

博客园 - 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