【发布时间】:2013-10-23 15:28:40
【问题描述】:
我在 Excel 中有这样的数据
table Cost_per_period
---------------------
ProjectId
FaseID
Period
Percentage
table cost_per_partner_per_fase
-------------------------------
ProjectID
FaseID
PartnerID
Amount
table partners
--------------
PartnerID
name
这是我想要的输出。
2012 2013 2014 2015
Project fase jan feb ... dec Q1 Q2 Q3 Q4 wholeY wholeY
------------------------------------------------------------------------
A310 1 100k 20k 10k 100k - 10k 10k 1000k 2000k
A310 2 110k - 20k 99k - 40k 50k 5000k 3000k
......
为了结合这些数据,我正在考虑做一个类似的 SQL 语句
SELECT cp.projectID, cp.faseID
, case when cp.period between '2012/01/01' and '2012/01/31'
THEN sum(cpf.amount)*cp.percentage as jan2012 end
, case when ..... as feb2012 end
, case .......
FROM cost_per_period as cp
INNER JOIN cost_per_partner_per_fase as cpf
on (cp.postjectid = cpf.projectid) and (cp.faseid = cpf.faseid)
GROUP BY cp.Projectid, cp.faseid
ORDER BY cp.ProjectID, cp.FaseID
我可以只使用 Excel 吗?我使用的是 excel 2007
【问题讨论】:
-
您可以使用不支持
CASE的 Access 数据库引擎(Jet、ACE 等)查询 Excel 工作簿。而是使用IIF(cp.period between CDATE('2012/01/01') and CDATE('2012/01/31'), sum(cpf.amount)*cp.percentage, NULL) as jan2012。 -
@onedaywhen,太好了,这就是我要说的。
标签: sql excel excel-2007 vba