分組後,統計記錄條數:
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;只是一個是子查詢(嵌套),一個是內置函數 dietinct();
數據庫結構