我经常需要计算表格中不同记录的数量。然而,在 MySQL 中都没有
select count(distinct *) from t;
也不
select count(distinct t.*) from t;
工作。我知道我可以解决这个问题
select count(*) as countdistinctrows
from (
select distinct * from t
) x;
但这很丑陋。真的没有办法询问不同行的数量吗?顺便说一下,
select distinct count(*) from t;
不是答案,因为 distinct 应用于表中的行数,因此给出相同的结果
select count(*) from t;
最佳答案
如果你不想使用它:
select count(*) as countdistinctrows
from (
select distinct * from t
) x;
我能想到的唯一选择是手动指定所有列名:
select count(distinct id, col1, col2, col3, ...)
from t;
关于mysql - 表中不同记录(行)的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36907817/