比如我工单A,存在材料B,C,D,E,F五种材料,如何写SQL语句,转换成图片中显示列,需要具体步骤谢谢。
通过子查询实现,5个查询变成5个列。
您好,我是有问必答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632
假设工单表为A,材料表为B
select a.*,(select 材料 from B where 工单=a.工单 and 材料= ‘B’ ) 材料1,(select 材料 from B where 工单=a.工单 and 材料= ‘C’ ) 材料2, (select 材料 from B where 工单=a.工单 and 材料= ‘D’ ) 材料3,(select 材料 from B where 工单=a.工单 and 材料= ‘E’ ) 材料4,(select 材料 from B where 工单=a.工单 and 材料= ‘F’ ) 材料5 from A a