MySQL分組后,統(tǒng)計(jì)記錄條數(shù)的方法:1、統(tǒng)計(jì)記錄條數(shù),代碼為【SELECT num,count(*) AS counts from test_a GROUP BY num】;2、對(duì)num去重后的數(shù)量的統(tǒng)計(jì)。
MySQL分組后,統(tǒng)計(jì)記錄條數(shù)的方法:
分組后,統(tǒng)計(jì)記錄條數(shù):
SELECT num,count(*) AS counts from test_a GROUP BY num;
查詢結(jié)果如下:
對(duì)num去重后的數(shù)量的統(tǒng)計(jì):
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;
它倆結(jié)果一樣,都是5;只是一個(gè)是子查詢(嵌套),一個(gè)是內(nèi)置函數(shù) distinct();
數(shù)據(jù)庫結(jié)構(gòu)