分组后,统计记录条数:

  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();

 

 

数据库结构

 

版权声明:本文为laowenBlog原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/laowenBlog/p/6081949.html