如何统计同一个表中名字之间的关系?
我有一个名为 names
的表,其中的行由名称和该名称的组组成。
我想计算任何两个名字在任何组中一起出现的次数。
表格
name | group
--------+------
Renato | 1
John | 1
Paul | 1
Renato | 2
John | 2
John | 3
Paul | 3
预期结果
name 1 | name 2 |count
--------+--------+-----
Renato | John | 2
Renato | Paul | 1
John | Renato | 2
John | Paul | 2
Paul | Renato | 1
Paul | John | 2
我该如何做到这一点?
I have a table called names
with rows consisting of a name and a group for that name.
I want to count how much times any two names appear together in any group.
Table
name | group
--------+------
Renato | 1
John | 1
Paul | 1
Renato | 2
John | 2
John | 3
Paul | 3
Expected result
name 1 | name 2 |count
--------+--------+-----
Renato | John | 2
Renato | Paul | 1
John | Renato | 2
John | Paul | 2
Paul | Renato | 1
Paul | John | 2
How I can do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为您提供所需的结构。我更新了 SQL,删除了对引号的需要,以满足那些能够正确识别引用不兼容但不愿意纠正它的人的需求。
Gives you the desired structure. I updated the SQL to remove the need for quotes, as to satisfy those, who are able to correctly identify a quoting incompatibility, but unwilling to correct it.