Mysql Pivot表:行列转换 [英] Mysql Pivot table : row column transformation
本文介绍了Mysql Pivot表:行列转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
表1:
DocId,DocumentName,ModuleId
表2:
Id,DocumentTypeId,ModuleId,ModuleDetailId。
想要创建一个文档名称为列标题的数据透视表
和whenTable2.DocumentTypeID = DocId然后将'Y'作为值
否则'N'
请建议asolution。
Table 1:
DocId,DocumentName,ModuleId
Table 2:
Id,DocumentTypeId,ModuleId,ModuleDetailId.
Want to create a pivottable with Document Name as Column headers
and whenTable2.DocumentTypeID = DocId then put 'Y' as Value
otherwise 'N'
Please suggest asolution.
推荐答案
那里有很多教程可以告诉你如何完成它(比如这个 [ ^ ]一)。但是,只有在知道DocumentName字段中的不同值的数量时,它才有效。如果是,您可以去查看该教程。如果没有,在我看来,转动桌子不是一个好主意。如果DocumentName字段上的值是动态的,我建议您只需在查询中加入表格,并添加一个附加字段,您可以在其中放置N和Y值。
There are a lot of tutorials available that tell you how to accomplish it (like this[^] one). However, it only works when you know the number of distinct values on your DocumentName field. If yes, you can go check that tutorial. If not, pivoting the table would not be a good idea in my opinion. If the values on your DocumentName field are dynamic, I suggest just joining the tables on your query and add an additional field where you can put the 'N' and 'Y' values.
这篇关于Mysql Pivot表:行列转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文