我可以使用 SQL 语句从工作表 A 中提取数据吗?仅使用 Excel 将工作表 B 转储到工作表 C 中
我在 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
I have data like this in Excel
table Cost_per_period
---------------------
ProjectId
FaseID
Period
Percentage
table cost_per_partner_per_fase
-------------------------------
ProjectID
FaseID
PartnerID
Amount
table partners
--------------
PartnerID
name
Here's the output I want.
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
......
To combine this data, I'm thinking of doing a SQL statement like
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
Can I do this using only Excel?, I'm using excel 2007
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下是针对 Excel 的最简单的查询,可以帮助您入门:
Here's the simplest of queries against Excel which may get you started:
这是取自 Excel 2007 中录制的对我有用的宏。您可以修改数据源和 SQL 查询以满足您的需要。
This is taken from a macro recorded in Excel 2007 that works for me. You can modify the data source and the SQL query to suit your need.
如果数据已存在于 Excel 中,则无法对其运行 SQL 查询。您只能针对 SQL 数据库运行此类代码(例如,如果您在 Access 中拥有数据)。
但是,您可以在 VBA 中编写等效函数并在 Excel 中运行它。
我还发现这个插件可以让你对 Excel 数据执行 SQL:http://www.querycell.com/
但它不是免费的,我不知道它有多好。
If the data is already in Excel, you can't run an SQL query against it. You'd only be able to run that kind of code against an SQL database (eg if you had the data in Access to start with).
However, you can write an equivalent function in VBA and run that in Excel.
I also found this plug in that would let you execute SQL against Excel data: http://www.querycell.com/
but it's not free and I have no idea how good it is.