MySQL分组后,如何统计记录条数
来源:动视网
责编:小采
时间:2020-11-08 22:13:26
MySQL分组后,如何统计记录条数
MySQL分组后,如何统计记录条数:MySQL分组后,统计记录条数的方法:1、统计记录条数,代码为【SELECT num,count(*) AS counts from test_a GROUP BY num】;2、对num去重后的数量的统计。MySQL分组后,统计记录条数的方法:分组后,统计记录条数:SELECT num,count(*)
导读MySQL分组后,如何统计记录条数:MySQL分组后,统计记录条数的方法:1、统计记录条数,代码为【SELECT num,count(*) AS counts from test_a GROUP BY num】;2、对num去重后的数量的统计。MySQL分组后,统计记录条数的方法:分组后,统计记录条数:SELECT num,count(*)

MySQL分组后,统计记录条数的方法:
分组后,统计记录条数:
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();
数据库结构

更多相关免费学习推荐:mysql教程(视频)
MySQL分组后,如何统计记录条数
MySQL分组后,如何统计记录条数:MySQL分组后,统计记录条数的方法:1、统计记录条数,代码为【SELECT num,count(*) AS counts from test_a GROUP BY num】;2、对num去重后的数量的统计。MySQL分组后,统计记录条数的方法:分组后,统计记录条数:SELECT num,count(*)