CREATE TABLE Book_Master(
Book_code NUMBER(10) PRIMARY KEY,
Book_name VARCHAR2(50) NOT NULL,
Book_pub_year NUMBER,
Book_pub_author VARCHAR2 (50) NOT NULL);
INSERT INTO book_master VALUES(10000001,'Let Us C++',2000,'Yashavant Kanetkar');
INSERT INTO book_master VALUES(10000002,'Mastersing VC++',2005,'P.J Allen');
INSERT INTO book_master VALUES(10000003,'JAVA Complete Reference',2004,'H.Schild');
INSERT INTO book_master VALUES(10000004,'J2EE Complete Reference',2000,'H. Schild');
INSERT INTO book_master VALUES(10000005,'Relational DBMS',2000,'B.C. Desai');
INSERT INTO book_master VALUES(10000006,'Let Us C',2000, 'Yashavant Kanetkar');
INSERT INTO book_master VALUES(10000007,'Intoduction To Algorithams',2001,'Cormen');
INSERT INTO book_master VALUES(10000008,'Computer Networks',2000,'Tanenbaum');
INSERT INTO book_master VALUES(10000009,'Introduction to O/S',2001,'Millan');
答案 0 :(得分:0)
select Book_pub_author, Book_name
from book_master
where Book_pub_author in ( select Book_pub_author
from book_master
group by Book_pub_author
having count(1)>1 )
order by Book_pub_author, Book_name
答案 1 :(得分:0)
您也可以使用内部联接而不是IN子句
Select Book_pub_author
, Book_name
from book_master b
INNER JOIN (
select Book_pub_author
from book_master
group by Book_pub_author
having count(1)>1
) t on t.Book_pub_author = b.Book_pub_author
你可以使用group_concat
获取同一行中的所有书籍Select Book_pub_author
, group_concat(Book_name )
from book_master b
INNER JOIN (
select Book_pub_author
from book_master
group by Book_pub_author
having count(1)>1
) t on t.Book_pub_author = b.Book_pub_author
group by Book_pub_author