You are on page 1of 4

IDNO: NAME: Terminal NO: [A]

Page 1 of 4

BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI
II SEMESTER 2011-2012
CS C352 DATABASE SYSTEMS
Date: 26
th
April 2012 Time: 90 minutes Weightage: 15%
Instructions:
1. Write a single SQL query for each question.
2. DO NOT create views unless asked in the question
3. DO NOT create any temporary tables.
4. Write legibly. Overwritten answers will not be considered for rechecks.
Consider the following scheme that is designed to capture the ratings of movies by users. Users table stores
the demographic information about the users. The zipcodes table contains the city and state information for
the zipcodes. Zipcode is referenced by users table. Movies table stores the information about movies. The last
19 fields in movies table are the genres, a 1 indicates the movie is of that genre, a 0 indicates it is not; movies
can be in several genres. Rating table contains the ratings given by users for movies. Userid and movieid refer
to the users and movies tables respectively.

Users:
userid | age | gender | occupation | zipcode
Zipcodes:
zipcode | zipcodetype | city | state
Movies table:
movieid | title | releasedate | unknown | Action | Adventure | Animation |
Children | Comedy | Crime | Documentary | Drama | Fantasy |
Film_Noir | Horror | Musical | Mystery | Romance | Sci_Fi |
Thriller | War | Western |
Rating:
userid | movieid | rating | timestamp

Create tables: Run the following queries.
create table users as select * from haribabu.users;
create table zipcodes as select * from haribabu.zipcodes;
create table movies as select * from haribabu.movies;
create table rating as select * from haribabu.rating;

Answer the following questions in this sheet itself.
Q1. List the distinct userids (sorted by age asc) who are from city ' MANCHESTER' and rated action and thriller movies.
Ans: No. of output records: ___ Write first 5 records below.[1]

Query:








Q2. List the states (sorted by state asc) that have more than 300 cities. [1]
Ans: No. of output records: ___ Write first 5 records below.

Query:








IDNO: NAME: Terminal NO: [A]
Page 2 of 4



Q3. List out the movie ids (sorted by release date asc) released in the same month and the year.
Ans: No. of output records: ___ Write first 5 records below. [2]

Query:




















Q4. With the available zipcode data, state wise list the movies (sorted by movie id asc) that are maximum rated in
that state. [2]
Ans: No. of output records: ___ Write first 5 records below.

Query:






















Q5. List out the movie ids (sorted by movie id) rated by all users. [2]
Ans: No. of output records: ___ Write first 5 records below.

Query:


IDNO: NAME: Terminal NO: [A]
Page 3 of 4
















Q6. List the movie ids (sorted by movied id asc) for which female have rated higher than the male. [2]
Ans: No. of output records: ___ Write first 5 records below


Query:

















Q7. List the movie ids (asc) which have higher average rating than overall average movie rating[2].
Ans: Total output records: ___ Write first 5 records below

Query:








IDNO: NAME: Terminal NO: [A]
Page 4 of 4

Q8. Write a stored procedure named stats that displays the following statistics. Explicit cursor must be used.[3]
a. Correlation between rating and age. Covariance is computed as given blow. y x, indicates the averages over
x and y.

a)Ans:
b. Compute the participation percentage state wise. List top 5 states.
b)Ans:
Procedure:

You might also like