17,078
社区成员
发帖
与我相关
我的任务
分享
SQL> create table ta(
2 name_id int,
3 record_A nvarchar2(20),
4 record_B nvarchar2(20)
5 );
Table created
SQL> create table tb(
2 name_id int,
3 name nvarchar2(20)
4 );
Table created
SQL> insert into ta
2 select 1,'aaa','xxx' from dual
3 union
4 select 1,'bbb','yyy' from dual
5 union
6 select 1,'ccc',null from dual
7 union
8 select 2,'ddd','zzz' from dual;
4 rows inserted
SQL> insert into tb
2 select 1,'namea' from dual
3 union
4 select 2,'nameb' from dual;
2 rows inserted
SQL> select b.name,count(a.record_a),count(a.record_b) from ta a
2 inner join tb b on a.name_id=b.name_id
3 group by b.name;
NAME COUNT(A.RECORD_A) COUNT(A.RECORD_B)
---------------------------------------- ----------------- -----------------
namea 3 2
nameb 1 1