如何将一行中的字段转换为列?
我有一个表,其中包含以下列:
Cost Rate
Repair 12
Repair 223
Wear 1000
Wear 666
Fuel 500
Repair 600
Fuel 450
Wear 400
我希望将此数据作为列(修复、磨损、燃料):
Repair Wear Fuel
825 2066 950
我如何使用 MS Access 查询来执行此操作?
I have a table with columns such as:
Cost Rate
Repair 12
Repair 223
Wear 1000
Wear 666
Fuel 500
Repair 600
Fuel 450
Wear 400
and I want this data as columns(Repair,Wear,Fuel) as:
Repair Wear Fuel
825 2066 950
How could I do this using an MS Access Query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
虽然有一个传统的 SQL 解决方案非常笨拙,但阅读此页面会引起警惕我注意到 MS Access 有一个 TRANSFORM ... PIVOT 语句您可能应该研究并使用来执行此操作。
我不能确定,但它应该看起来像:
而且它可以变得比这更奇特。 例如
While there's a traditional SQL solution for this that is pretty kludgy, reading this page alerted me to the fact that MS Access has a TRANSFORM ... PIVOT statement you probably should look into and use to do this.
I can't be certain but it should look like:
And it can get fancier than this. E.G.
未经测试但是
untested but
可以使用此查询,
如果您使用的是 Oracle,则
否则,如果使用任何其他数据库引擎,您可以在此查询之前快速执行一条语句
you can use this query
if you are using Oracle
otherwise, if any other database engine, you can make a quick statement right before this one
您可以使用交叉表查询来完成此操作。 “访问查询”窗口中有一个向导将引导您创建一个。 只需单击“新建查询”按钮并选择“交叉表查询向导”即可。
You can do this with a Crosstab query. There is a wizard in the Access Queries window that will walk you through creating one. Just click the New Query button and select the Crosstab Query Wizard.
这将获得您需要的数据:
然后您可以以您喜欢的方式呈现它。
This will get the data you need:
and then you can present it whichever way you like.