Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
2Activity
0 of .
Results for:
No results containing your search query
P. 1
CSCI235 Spring 2010 Tutorials Query Examples

CSCI235 Spring 2010 Tutorials Query Examples

Ratings: (0)|Views: 124|Likes:
Published by technofreak9
SQL Queries. Loads of them.
SQL Queries. Loads of them.

More info:

Published by: technofreak9 on May 25, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

08/12/2010

pdf

text

original

 
University of Wollongong in DubaiCSCI 235 – DatabasesSelect Queries Examples
Task 1
This task refers to the library database discussed and implemented in Week 3 lab class.The relational schema is repeated below:Book (ISBN, title, publisher, version_no)WrittenBy (ISBN, authorname, yrpublished, no_of_copies)Author (authorname, sex, age , nationality)Formulate SQL queries for the following requests:
1.Find the names of Authors who wrote both Informatics and Databasesbooks.
Select w.authornameFrom WrittenBy w, Book bWhere w.ISBN = b.ISBN and w.title = ‘Informatics’INTERSECTSelect w1.authornameFrom WrittenBy w1, Book b1Where w1.ISBN = b1.ISBN and w1.title = ‘Databases’
2.Find the ISBN of Books which is written by Benoit or Nolan.
Select w.ISBNFrom WrittenBy w,Where w.authorname = ‘Benoit’INTERSECTSelect w1.ISBNFrom WrittenBy w1Where w1.authorname = ‘Nolan’
3.Find the names of Authors who wrote SQL Primer but not Databases.
Select w.authornameFrom WrittenBy w, Book bWhere w.ISBN = b.ISBN and w.title = ‘SQL Primer’INTERSECTSelect w1.authornameFrom WrittenBy w1, Book b1Where w1.ISBN = b1.ISBN and w1.title = ‘Databases’
 
4.Find the names of Authors who wrote at least one book.
Select w.authornameFrom WrittenBy w;
5.Find the names of Books which were published in 1998.
Select b.titleFrom Book b, WrittenBy wWhere b.ISBN = w.ISBN and w. yrpublished = 1998
6.Find the names of Authors who didn’t write a book.
Select a.authornameFrom author AWhere authorname NOT IN(Select w.authornameFrom WrittenBy w)
7.Find the names of Authors who wrote Informatics. (use Exist)
Select a.authornameFrom Author aWhere EXISTS (Select w.authornameFrom WrittenBy w, Book bWhere w.ISBN = b.ISBN and b.title = ‘Informatics’ and
a.authorname =w.authorname
)
8.Find Authors who are older than some author from Australia.
Select a1.authornameFrom author a1Where a1.age > ANY(Select a.ageFrom Author aWhere nationality = ‘Australian’)
9.Find Authors who are older than all authors from Australia.
Select a1.authornameFrom author a1Where a1.age > ALL(Select a.ageFrom Author aWhere a.nationality = ‘Australian’)10.
List the ISBN and title of all books with at least one Australian author.
Select b.title, b.ISBNFrom Author a, Book b, WrittenBy w
 
Where a.authorname = w.authorname and b.ISBN=w.ISBN anda.nationality=’Australian’
11.Find the names of all female authors who wrote databases.
Select a.authornameFrom Author a, Book b, WrittenBy wWhere a.authorname = w.authorname and b.ISBN=w.ISBN and a.sex= ‘Female’and b.title = ‘Databases’12.
Find the average age of authors.
Select AVG (age)From author 13.
Find the average age of authors who are not Italian.
Select AVG (age)From author Where nationality <> ‘Italian’
14.Find the name and nationality of oldest and youngest Author.
Oldest:Select a1.name, a1.nationalityFrom author a1Where a1.age = (Select MAX(a.age) From Author a)Youngest:Select a1.name, a1.nationalityFrom author a1Where a1.age = (Select MIN(a.age) From Author a)
15.Find the number of books which their version number is greater than 1.
Select count(*)From Book bWhere b.version_no > 116.
Find the names of authors who are older than the oldest author who isAustralian.
Select a1.nameFrom author a1Where a1.age > (Select MAX(a.age)From Author aWhere a.nationality = ‘Australian’)
17.Find the average age of authors for each nationality that has at least oneauthor.
Select AVG (age)From Author a

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->