合并具有匹配 id 的行的最佳方法
我有一张家庭表,其中包含地址信息和城市信息 然后我有家庭中所有人的个人表 可以是家庭成员 1 人,也可以是 10 人 我想要实现的是,如果个人属于同一家庭,则信息将显示在同一行中,家庭信息全部显示在 1 行中 因此,如果有 10 人,信息仍将位于 1 行,如果有 2 人,信息仍将位于 1 行
household table
1 bekshire st dell MA 10001 02639 50 0002 dell NULL ALRGEN
BERKSHIRE ST NULL NULL NULL NULL
individuals that belong to household id 10001
first last code
BOB BUILDER U
JESS BUILDER A
i want
1 bekshire st dell MA 10001 02639 50 0002 dell NULL ALRGEN 1 BERKSHIRE ST BOB,JESS BUILDER U,A
i have a table of households which has the address information and city info
and then i have and individuals table of all the people in the household
it could be 1 person that belongs to the house hold or it could be 10
what i want to achieve is that if the individuals belong to the same household there information will show up in the same row as the household information all in 1 row
so if theres 10 people the inforamtion will still be in 1 row, if theres 2 people still only 1 row
household table
1 bekshire st dell MA 10001 02639 50 0002 dell NULL ALRGEN
BERKSHIRE ST NULL NULL NULL NULL
individuals that belong to household id 10001
first last code
BOB BUILDER U
JESS BUILDER A
i want
1 bekshire st dell MA 10001 02639 50 0002 dell NULL ALRGEN 1 BERKSHIRE ST BOB,JESS BUILDER U,A
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这如此困难的原因是 SQL 偏向规范化和结构,而本质上你要求的是相反的方向。我知道我没有直接回答您的问题,但也许您最好的选择是考虑在客户端操作和显示数据,并坚持使用简单的查询来从数据库获取数据。
The reason this is so hard is that SQL favors normalization and structure, and essentially what your asking for is to go the opposite direction. I know I'm not directly answering your question, but maybe your best bet is to consider manipulating and displaying the data on the client side and stick to simple queries to get the data from the database.