--不太明白你的意思 是这个? select count(*) from table group by na,nb --或者是? select count(distinct na) from table union select count(distinct nb) from table
SELECT COUNT(*) FROM ( SELECT DISTINCT na, nb FROM table ) t;
select count(*) from table group by na,nb
那就分组后算统计数:select count(*) from table group by na,nb
select count(distinct na || nb) from table 你好,如果你只关心count数这样应该可以
注意了,如果你要的是计算(a 列和 b列的组合条数 重复的不能计算在内)的条数,这个就可以 select count(*),na,nb from table group by na,nb; 但如果你要的是显示(a 列和 b列的组合条数 重复的不能计算在内)的所有记录,那么 select distinct na,nb from table; 就可以了。
select count(distinct na||nb) from table
--你写的有语法问题 select count(*) from table group by na,nb --or select count(*) from (select distinct na,nb from table)
我想我明白LZ的意思了,用这个 SELECT COUNT(*) FROM ( SELECT DISTINCT na, nb FROM table ) t;
比如用在sum时可能需要SUM(A)/count(distinct na||nb)
select count(1) from (select na,nb from table group by na,nb)
18楼的第二个 select count(*) from (select distinct na,nb from table) 第一个少套了一层
想了想,也可以用||,不过得加个数据中不会出现的字符加在中间,避免上面所说的错误. 比如 select distinct na||'-'||nb from table
SELECT COUNT(1) FROM (SELECT DISTINCT NA,NB from table) a;
哎 还是在itpub的大牛给解决了 with t as ( select 1 as a, 5 as b from dual union all select 1 as a, 5 as b from dual union all select 2 as a, 8 as b from dual union all select 1 as a, 7 as b from dual ) SELECT COUNT(COUNT(*)) FROM t GROUP BY a,b;
--不太明白你的意思 是这个?
select count(*) from table group by na,nb
--或者是?
select count(distinct na) from table
union
select count(distinct nb) from table
SELECT DISTINCT na, nb FROM table
) t;
select count(distinct na || nb) from table
你好,如果你只关心count数这样应该可以
select count(*),na,nb from table group by na,nb;
但如果你要的是显示(a 列和 b列的组合条数 重复的不能计算在内)的所有记录,那么
select distinct na,nb from table; 就可以了。
select count(distinct na||nb) from table
select count(*) from table group by na,nb
--or
select count(*) from (select distinct na,nb from table)
SELECT COUNT(*) FROM (
SELECT DISTINCT na, nb FROM table
) t;
select count(1)
from (select na,nb from table group by na,nb)
select count(*) from (select distinct na,nb from table)
第一个少套了一层
比如 select distinct na||'-'||nb from table
(SELECT DISTINCT NA,NB from table) a;
with t as
(
select 1 as a, 5 as b from dual
union all
select 1 as a, 5 as b from dual
union all
select 2 as a, 8 as b from dual
union all
select 1 as a, 7 as b from dual
)
SELECT COUNT(COUNT(*)) FROM t GROUP BY a,b;