如何合并和计算除 ID 列之外相同的 MySQL 行?
我希望能够合并行并找出除 ID 之外有多少行是相同的。例如,如果我有这个表:
+---------+-----------+-----------+
| ID | Col 1 | Col 2 |
+---------+-----------+ ----------+
| 1 | 1 | 5 |
| 2 | 1 | 5 |
| 3 | 4 | 9 |
| 4 | 3 | 9 |
| 5 | 1 | 5 |
| 6 | 1 | 5 |
| 7 | 1 | 5 |
| 8 | 4 | 9 |
+---------+-----------+-----------+
它将变成:
+---------+-----------+-----------+---------+
| ID | Col 1 | Col 2 | Count |
+---------+-----------+ ----------+---------+
| 1 | 1 | 5 | 5 |
| 2 | 4 | 9 | 2 |
| 3 | 3 | 9 | 1 |
+---------+-----------+-----------+---------+
这个查询是什么?
I want to be able to merge rows and find out how many are the same excluding the ID. For example, if I was to have this table:
+---------+-----------+-----------+
| ID | Col 1 | Col 2 |
+---------+-----------+ ----------+
| 1 | 1 | 5 |
| 2 | 1 | 5 |
| 3 | 4 | 9 |
| 4 | 3 | 9 |
| 5 | 1 | 5 |
| 6 | 1 | 5 |
| 7 | 1 | 5 |
| 8 | 4 | 9 |
+---------+-----------+-----------+
It would become:
+---------+-----------+-----------+---------+
| ID | Col 1 | Col 2 | Count |
+---------+-----------+ ----------+---------+
| 1 | 1 | 5 | 5 |
| 2 | 4 | 9 | 2 |
| 3 | 3 | 9 | 1 |
+---------+-----------+-----------+---------+
What would the query for this be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在结果中的 ID 列旁边,对我来说,您似乎需要:
beside the ID column in your result, to me it looks like you need: