这是官方手册的一句话:
In MySQL, you can obtain the number of distinct expression combinations that do not contain NULL by giving a list of expressions. In standard SQL, you would have to do a concatenation of all expressions inside COUNT(DISTINCT …).
能解释一下吗?
In MySQL, you can obtain the number of distinct expression combinations that do not contain NULL by giving a list of expressions. In standard SQL, you would have to do a concatenation of all expressions inside COUNT(DISTINCT …).
能解释一下吗?
解决方案
20
就是说在mysql中,可以这么写,里面可以有多个字段count(distinct 多个字段):
mysql> select count(distinct id,v) from tb_m; +--+ | count(distinct id,v) | +--+ | 1 | +--+ 1 row in set (0.04 sec)
这个是mysql特有的语法,而一般其他的数据库,例如oracle,sql server,只能这么写一个字段count(distinct 一个字段):
mysql> select count(distinct id) from tb_m; +--+ | count(distinct id) | +--+ | 1 | +--+ 1 row in set (0.12 sec)
20
select count(*) from (select distinct id from tb_m) t