Reputation: 15
I would create this table.
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)
)
I have no Oracle installed now but I wanna select
Date difference (number of years) between first and last book per each author.
I think there should be some aggregate function.
Upvotes: 0
Views: 77
Reputation: 17920
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
Upvotes: 1