mysql - mysql无法在视图中显示重复的条目
解决方案
用于group_concat()
聚合 id 并对表进行自连接:
select t.id, t.name,
group_concat(tt.id order by tt.id) repeated
from tablename t left join tablename tt
on tt.name = t.name and tt.id <> t.id
group by t.id, t.name
order by t.id
请参阅演示。
结果:
| id | name | repeated |
| --- | ----- | -------- |
| 1 | John | 4,8 |
| 2 | Smith | 3 |
| 3 | Smith | 2 |
| 4 | John | 1,8 |
| 5 | Anna | |
| 6 | David | 7 |
| 7 | David | 6 |
| 8 | John | 1,4 |
推荐阅读
- java - 计算字符串数组的每个字符串中的反斜杠
- javascript - 文本淡入时无样式内容的闪烁
- python - 试图让精灵的一部分改变颜色,但整个精灵会改变
- r - 如何从地理栅格中获取“ppm”的协变量数据?
- ruby-on-rails - 如何为可以访问 cookie 和会话的控制器创建 rails 服务
- python - 给定一个列表列表返回列表中的整数值列表
- python - how do I make empty lists based on a number of input information?
- r - 使用 r 绘图时如何调整图片的长度和宽度
- python-3.x - 使用 python 进行 Yolo-v3 对象检测
- typescript - 如何将 AWS CDK 合成器输出到终端/网络浏览器 [如果可能]