简体   繁体   English

使用SQl Server如何在父子关系中显示数据

[英]using SQl Server How to show Data in parent child Relationship

Here i have Two Tables like 我在这里有两张桌子

Master

Id       MasterName
1         Electronic
2         HomeNeeds

ChildTable ChildTable

Ch_Id      Ch_Name      Master_Id
1            L.G            1
2            Nokia           1
3             WoodLand        2

Please Help me How can i display Data in pArrent child relation Ship Like in Table it should display Like 请帮我如何在pArrent子关系中显示数据Ship Like in Table,它应该显示Like

Id   Product
1    Electronic
  (Within This)
   Lg 
   Nokia

I kNow Joins but its will not helpful for me 我现在加入,但对我没有帮助

Try something like: 尝试类似:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM