我在 MySQL 数据库中有一个表:
number | string
-------+-------
318 | no
504 | no
318 | yes
504 | no
60 | yes
我想要计算出现次数并删除重复项,将计数添加到 SELECT
语句中的剩余行:
number | string | count
-------+--------+------
60 | yes | 1
318 | no | 1
318 | yes | 1
504 | no | 2
尽管答案为 this related question ,当我有多个列时,我无法思考要计算什么才能获得此结果。
最佳答案
我认为您只想在 GROUP BY
子句中包含多个列。这应该有效:
SELECT number, string, COUNT( number ) AS count
FROM foo
GROUP BY number, string
ORDER BY number, string
关于mysql - 计算多个列中的重复项并在 MySQL SELECT 语句中删除它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27528545/