SQL x-ref 查询返回可变数量记录的单行
我有一个父母
表(表中真实的妈妈和爸爸父母姓名),一个孩子
表(这些是父母的孩子,名字和姓氏)和一个 x-ref
表:xref-id、parent-id 和 child-id。
外部参照表用于容纳妈妈/爸爸组合可能拥有的不同数量的孩子。
我需要一个查询来返回一行父母和孩子的姓名。我面临的问题是有些父母有1个孩子,有些父母有超过1个孩子。
我很困惑...
TLB_PARENT:
p_id, momfname, dadfname
TLB_CHILD:
c_id, childfname, childlname
TLB_XREF
xref_id, p_id, c_id
非常感谢任何帮助!
I have a table of parents
(real mom & dad parent names in a table), a table of children
(these are children of the parents, first and last name) and an x-ref
table: xref-id, parent-id and child-id.
The xref table is to accommodate the variable number of children a mom/dad combo could have.
I need a query to return a single row of parents and children names. The problem I am facing is some parents have 1 child, some have more than 1 child.
I'm quite stumped...
TLB_PARENT:
p_id, momfname, dadfname
TLB_CHILD:
c_id, childfname, childlname
TLB_XREF
xref_id, p_id, c_id
Any help is really appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SQL 查询的 culmns 数量不是动态的,它是非常固定的。
最接近的就是决定孩子的最大数量。然后,许多单元格中都会有空白,但更重要的是,表格可能会被填满,而某些子项可能不会显示。
如何执行此操作取决于您所拥有的 SQL 版本。
另外,请注意,您可以在现实生活中遇到这种情况...
虽然这有点混乱的世界,但我知道一些家庭真的很混乱。我只是指出,您的简化可能会在任何规模较大的现实世界人口中出现问题。
The number of culmns is a SQL Query is not dynamic, it's very firmly fixed.
The closest you can get is deciding on a maximum number of children. You'll then have blanks in many cells, but more importantly, the possibility that the table gets filled and some children don't get displayed.
How to do this depends on the version of SQL you have.
Also, note that you can have this scenario in real life...
Although that's a bit of a messy world, I know some really really messy families. I'm just pointing out that your simplification is likely to have issues in any decent sized real world population.