如何透视MS Access表 [英] How to pivot a ms access table
问题描述
我有以下数据
表:人
如何复制以下结果
否,没有订单,没有ID.这是由存储基本数据的普通人完成的,我正在尝试产生这些结果以将其存储到postgres服务器中.
No there is no order and there is no ID. This was done by an average guy storing basic data, and I'm trying to produce these results to store it into the postgres server.
我看到了by的使用,但实际上我对如何以这种方式产生这样的结果一无所知.
I saw the use of partition by but I am actually lost as to how to produce such results in such a fashion.
这是sql查询的示例代码,尽管实际上并没有太多内容
Here is a sample code for the sql query though there is not much to really go on
Select mother,father,child
from persons
order by mother, father
这正在使用Access 2010女士.这可以解决吗?
推荐答案
如果存在唯一的标识符字段,则使用DCount的CROSSTAB查询可以完成.在表中添加一个自动编号字段.
A CROSSTAB query using DCount can accomplish if there is unique identifier field. Add an autonumber field to the table.
TRANSFORM First(Persons.Child) AS FirstOfChild
SELECT Persons.Mother, Persons.Father
FROM Persons
GROUP BY Persons.Mother, Persons.Father
PIVOT "Child" & DCount("*","Persons","Mother & Father='" & [Mother] & [Father] & "' AND ID<" & [ID])+1;
替代方法涉及VBA过程将记录写入另一个表.
Alternative involves VBA procedure writing records to another table.
这篇关于如何透视MS Access表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!