mysql 行列转换 pivot,Mysql Pivot表:行列转换

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.

解决方案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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值