获取单个oracle查询的行数和其他列值



考虑我下面有一个名为Book_detail和Author_detail的表:

使用您发布的示例数据:

SQL> with
2  book_detail (id, bookid, name) as
3    (select 1, 1001, 'ABC' from dual union all
4     select 2, 2001, 'XYZ' from dual
5    ),
6  author_detail (price, bookid, name) as
7    (select 100, 1001, 'Sham' from dual union all
8     select 200, 2001, 'Ram'  from dual union all
9     select 300, 3001, 'xxx'  from dual
10    )
11  select count(a.bookid) counta,
12         count(distinct b.id) countb,
13         b.id
14  from book_detail b join author_detail a on a.bookid = b.bookid
15  where a.bookid = 2001
16  group by b.id;
COUNTA     COUNTB         ID
---------- ---------- ----------
1          1          2
SQL>

相关内容

最新更新