如何构建数据表或构建查询以获得此最终结果 [英] How can Build Datatable or Build Query to Get this Final result
本文介绍了如何构建数据表或构建查询以获得此最终结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好这是我的方案。
请查看此链接>它会详细解释。
http://snag.gy/ffC8r.jpg [ ^ ]
我使用MySQL和C#,我认为这样会更好理解我创建了这个图像。
谢谢:)
Hi all This is my scenario.
Please check out this link> it will explain in detail.
http://snag.gy/ffC8r.jpg[^]
Im using MySQL and C#, I think it will better to understand so I created this Image.
Thanks :)
推荐答案
我认为这正是你想要的......
I think this is exactly what you want..
Declare @Colms varchar(max)=''
SELECT
@Colms= Stuff((SELECT ', [' + cast(s as varchar(max))+']'
FROM
(select distinct AA as s from YYYY where id in (select id from xxxx)) x
For XML PATH ('')),1,1,'')
exec('select id,A,B,C,D,'+@Colms+'
from
(
select p.*,q.AA,q.BB from xxxx p left join YYYY q on p.id=q.id
) x
pivot
(
max(BB)
for AA in('+@Colms+')
)p ')
这篇关于如何构建数据表或构建查询以获得此最终结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文