sql - 使用 SQL Server:如何在父子关系中显示数据
问题描述
我有两个这样的表:
掌握
Id MasterName
---------------------
1 Electronic
2 HomeNeeds
子表
Ch_Id Ch_Name Master_Id
-----------------------------------
1 L.G 1
2 Nokia 1
3 WoodLand 2
请帮助我-如何在父子关系中显示数据?
就像在表中一样,它应该显示 Like
Id Product
---------------
1 Electronic
(Within This)
Lg
Nokia
我知道加入,但它对我没有帮助
解决方案
尝试类似:
SELECT
M.MasterName,
STRING_AGG (c.ChildName, ', ') as products,
M.Id
FROM
Master AS M
JOIN
Child as C
ON M.Id = C.MasterId
GROUP BY
M.MasterName,
M.Id
推荐阅读
- r - bookdown-demo 可以构建 pdf 和 epub,但在创建 gitbook 时出错
- wpf - 如何使用样式/数据触发器在 datagridcell 中指定控件
- c# - 是否有 .NET (Core) 等效的 npm 链接?
- java - 如何创建将二进制转换为十进制的程序
- java - java.lang.NoClassDefFoundError: org/apache/kafka/clients/producer/Producer
- flutter - 在提供者构造函数中初始化 bloc 与初始化 bloc 实例变量的内联声明
- javascript - 表格组件在 IE11 下不渲染,给出:“渲染错误:”TypeError:对象不支持属性或方法“条目””
- twilio - 如何在 Twilio Autopilot Say 操作中使用 SSML
- r - 成对子表
- html - 当他的孩子是宽度为:auto 的 img 时,如何让 Firefox 正确计算宽度?(在相对位置包装器中)