|
Re: 这种情况如何用SQL语句实现
You can use outer join to get what you wanted.
Try this:
create table books (book# interger, author char(30));
insert into books values(123, 'Peter');
insert into books values(123, 'David');
insert into books values(123, 'John');
with temp as (select c1.book# as book, c1.author as author1, c2.author as author2, c3.author as author3
from books as c1 left outer join books as c2
on c1.book# = c2.book# left outer join books as c3 on c2.book# = c3.book#
and c1.author = 'Peter' and c2.author = 'David' and c3.author = 'John')
select * from temp where author1 is not null and author2 is not null and author3 is not null;
Jimruski
最初由 oracle96 发布
[B]I have a table about the book and author relationship.
Book Author
---- ------
123 Peter
123 David
123 John
How can I use a single sql query to get the result:
Book Author
---- ------
123 Peter,David,John [/B] |
|