select count(distinct A) from tablename union all select count(distinct B) from tablename --例如 SQL> select count(distinct empno) from emp 2 union all 3 select count(distinct deptno) from emp;COUNT(DISTINCTEMPNO) -------------------- 14 3
--难道是这样? select count(*) from table group by A,B
select count(*) from table where A='A'select count(*) from table where B='Y'这两个数据集查着是分开的,用一条语句得到这两条语句的结果,输出结果示例 countA countB ------------- 4 4
select a, count(a) from table_ab group by a union select b, count(b) from table_ab group by b;不過a和b字段類型應該要一樣才行
select sum(decode(b,'y',1,0)),sum(decode(A,'a',1,0)) from tb
select m.*, n.* from (select count(*) from table where A='A') m, (select count(*) from table where B='Y')
select SUM(decode(A,'A',1,0)) countA ,SUM(decode(B,'Y',1,0))countB from table ;
select sum(case when A='A' then 1 else 0 end) , sum(case when B='Y' then 1 else 0 end) from tb
select SUM(decode(A,'A',1,0)) countA ,SUM(decode(B,'Y',1,0))countB from table ;
select count(case when A='A' then 1 else null end) , count(case when B='Y' then 1 else null end) from tb select (select count(*) from tb where A='A'), (select count(*) from tb where B='Y') from dual
select (select count(*) from tb where A='A'), (select count(*) from tb where B='Y') from dual 这个也
create table aa(a varchar2(4),b varchar2(4));
select * from ( select count(*),a from aa group by a union select count(*),b from aa group by b);
结果是: COUNT(*) A ---------- ---- 2 B 3 N 4 Y 5 A
全是SQL啊。哈哈。都是高手。
可以参考select count(decode(a,'A','A')),count(decode(B,'B','B')) from test_AB
SELECT count(A),count(b) FROM TABLE_NAME
select m.*, n.* from (select count(*) from table where A='A') m, (select count(*) from table where B='Y')
union all
select count(distinct B) from tablename
--例如
SQL> select count(distinct empno) from emp
2 union all
3 select count(distinct deptno) from emp;COUNT(DISTINCTEMPNO)
--------------------
14
3
select count(*) from table group by A,B
countA countB
-------------
4 4
from table_ab group by a
union
select b, count(b)
from table_ab group by b;不過a和b字段類型應該要一樣才行
(select count(*) from table where A='A') m,
(select count(*) from table where B='Y')
select SUM(decode(A,'A',1,0)) countA ,SUM(decode(B,'Y',1,0))countB
from table ;
sum(case when A='A' then 1 else 0 end) ,
sum(case when B='Y' then 1 else 0 end)
from tb
from table ;
count(case when A='A' then 1 else null end) ,
count(case when B='Y' then 1 else null end)
from tb
select (select count(*) from tb where A='A'),
(select count(*) from tb where B='Y')
from dual
select (select count(*) from tb where A='A'),
(select count(*) from tb where B='Y')
from dual
这个也
select * from (
select count(*),a from aa group by a
union
select count(*),b from aa group by b);
COUNT(*) A
---------- ----
2 B
3 N
4 Y
5 A
(select count(*) from table where A='A') m,
(select count(*) from table where B='Y')