合并具有匹配 id 的行的最佳方法

发布于 2024-12-01 06:15:06 字数 615 浏览 0 评论 0原文

我有一张家庭表,其中包含地址信息和城市信息 然后我有家庭中所有人的个人表 可以是家庭成员 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

微凉 2024-12-08 06:15:06

这如此困难的原因是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文