我会创建这个表。
create table Books
(
book_id number PRIMARY KEY,
Title number,
yearpub DATE,
author_id number
)
create table Authors
(
author_id number,
book_id number
)
create table Author_name
(
author_id number,
first_name varchar(10),
last_name varchar(10)
)
我现在没有安装Oracle,但我想选择 每位作者的第一本书和最后一本书之间的日期差异(年数) 我认为应该有一些集合功能。
答案 0 :(得分:1)
SELECT authors.author_id,
max(name.first_name||' '||name.last_name) as full_name,
max(to_char(yearpub,'yyyy')) - min(to_char(yearpub,'yyyy')) as years
from author_name name, books,authors
where
authors.author_id = name.author_id and
authors.author_id = books.author_id and
authors.book_id = books.book_id
group by authors.author_id