分组后,统计记录条数:
SELECT num,count(*) AS counts from test_a GROUP BY num;
查询结果如下:
对num去重后的数量的统计:
SELECT count(t.counts) FROM ( SELECT num,count(*) AS counts from test_a GROUP BY num ) AS t;
SELECT count(DISTINCT num) AS count FROM test_a;
它俩结果一样,都是5;只是一个是子查询(嵌套),一个是内置函数 distinct();
数据库结构