Beruflich Dokumente
Kultur Dokumente
Task 1
This task refers to the library database discussed and implemented in Week 3 lab class.
The relational schema is repeated below:
1. Find the names of Authors who wrote both Informatics and Databases books.
AUTHORNAME
---------------
Benoit
McAven
2 rows selected.
3 rows selected.
3. Find the names of Authors who wrote SQL Primer but not Databases.
AUTHORNAME
---------------
Nolan
1 row selected.
AUTHORNAME
---------------
Antonini
Benoit
McAven
Nolan
Williams
5 rows selected.
1 row selected.
AUTHORNAME
---------------
Gandhi
1 row selected.
AUTHORNAME
---------------
Antonini
Benoit
McAven
3 rows selected.
8. Find Authors who are older than some author from Australia.
4 rows selected.
9. Find Authors who are older than all authors from Australia.
AUTHORNAME
---------------
Williams
1 row selected.
10. List the ISBN and title of all books with at least one Australian author.
ISBN TITLE
---------- ---------------
202 SQL Primer
246 Databases
500 Infomatics
3 rows selected.
11. Find the names of all female authors who wrote databases.
SQL> select a.authorname
2 from Author a, Writtenby w, Book b
3 where b.ISBN=w.ISBN
4 AND w.authorname=a.authorname
5 AND a.sex='Female'
6 AND b.title='Infomatics';
AUTHORNAME
---------------
Benoit
McAven
2 rows selected.
AVG(AGE)
----------
53.1666667
13. Find the average age of authors who are not Italian.
AVG(AGE)
----------
57.2
1 row selected.
14. Find the name and nationality of oldest and youngest Author.
AUTHORNAME NATIONALIT
--------------- ----------
McAven Australian
1 row selected.
SQL> select authorname,nationality
2 from Author
3 where age=(select max(age) from author);
AUTHORNAME NATIONALIT
--------------- ----------
Williams British
1 row selected.
15. Find the number of books which their version number is greater than 1.
COUNT(*)
----------
3
1 row selected.
16. Find the names of authors who are older than the oldest author who is Australian.
17. Find the average age of authors for each nationality that has at least one author.
Author
Authorname Sex Age Nationality
Benoit Female 42 French
Nolan Male 65 Australian
Antonini Male 33 Italian
McAven Female 31 Australian
Williams Male 90 British
Ghandi Female 58 Indian
Book
ISBN Title Publisher Version_No
101 Databases Possum 1
202 SQL Primer Hall 2
246 Databases West 1
400 Modula 2 Possum 2
444 Advanced SQL Hall 1
500 Informatics Hall 4
WrittenBy
ISBN Authorname yrpublished no_of_copies
101 Benoit 1993 100
246 Williams 2000 120
246 McAven 2000 120
500 McAven 2002 90
500 Benoit 2002 90
500 Antonini 2002 90
202 Nolan 1998 130