Database Languages
eXercise #7
Questions on the
STUDENT Database
The following set
of activities will be performed on the STUDENT database, make your own copy with the script your teacher sent you via email so you can TRY your solutions after you have planned them.
Wherever possible, use the DIAGRAM method to plan your solution BEFORE translating to SQL:
where comptype is a text dessie; chip is processorname; RAM is in Gb; video is name of card; HDD is capacity of hard disk in Gb
What follows is
a list of activities for you to try ON PAPER. Due to the 'power' and versatility
of the SELECT statement, you will need to practise it's use, this exercise
set provides some examples.
Avoid the temptation
to 'short cut' through the exercises avoiding the function or convention
that is meant to be used for each of the exercise sets - you will learn
nothing if you do this, and all that will benefit is your typing skills.
Creating a Projection
- list student names
- list sid along
with birth and sibling information
- list all sports
played (with duplicates)
- list all types
of computers owned (with duplicates)
Removing Duplicates
- list all houses
(no duplicates)
- list all suburbs
(no duplicates)
- list all studied
subjects (no duplicates)
- list all sports
(no duplicates)
- list all hobbies
(no duplicates)
- list all HDD
capacities (no duplicates)
**NB** ASSUME LISTS
ARE DISTINCT FROM NOW ON (but restrict use of the DISTINCT keyword to
situations where it does something useful)
Selecting Rows
- list name of
students born first in their families
- list name and
nickname of students born second in a 3 child family
- list sports associated
with someone who has a SID of "s9103456" (or pick another one that gives data)
- list all sids
who study both English and Physics
- list all sids
who study Maths C
- list Treacy tutors
- list names of
students without computers
Using the Relational
and Logical Operators (and, or, not)
- list all students
who were born either first or second
- list all students
not born last
- list all students
who appear alphabetically lower in the class list than yourself
- list all sids
who don't play rugby
- list all sids
who don't study EConomics
- list all sids
that study both Maths B and Maths C
- list all students
whose computers have less that 1 Gb of RAM (is this even possible?)
- list all Barrett
students that were born first
Negated Conditions
- list all students
who are not from Corinda, Indooroopilly or Oxley
- list all sports
that are not rugby (negated form - use a NOT somewhere in your answer)
The Condition IS
[NOT] NULL
- list all students
whose nickname is unknown
- list those students
who don't know what chip their computer has
The BETWEEN..AND
Construction
- list all students
that are in Windsor tutor groups lettered between A & D
- list students
with sids between s910000 and s920000 (or make up some boundaries that work)
- list students
not born first (trickey, use a between and if you can)
- list all student
but those students not born second
The LIKE Operator
- list all students
who have a surname starting with 'B'
- list all sports
starting with 'S'
- list all students
with a 'W' in their name
- list all students
with a first name exactly 6 letters long
- list all students
with and 'IBM' style computer
The IN Operator
- list all students
living in either Corinda or Aspley (use IN)
- list all students
from a 1, 2 or 3 child family (use IN)
- list all sids
studying either EConomics, Maths B or Modern History (use IN) with
no repeat sid values.
Ordering on a single
column
- list all students
in alphabetical order
- list all sports
(no repeats) in alphabetical order
- list all subjects
in reverse alphabetical order (no repeats)
- list all students
and suburbs they live with suburb arranged alphabetically
- list all nicknames
in reverse alphabetical order (no nulls)
- list students
arranged in order of their tutor group within their houses (a two
column sort)
Banding (or Ordering)
- list all sids
and sports, banded by sport
- list all surnames,
banded by month born
Deriving Simple
Statistics
- derive the number
of sids studying ACounting
- derive the number
of siblings for the class
- derive the number
of student not taking Modern History
- derive the number
of students in year 11 IPT
Performing Simple
Calculations
- derive the student
name with the largest sid
- derive the number
of rows in each of the five tables (separately)
- derive the average
sibling position for the group (sum of measurements divided by the
number of measurements)
- derive the name
of the student with the largest number of brothers and or sisters
Use for Column
Numbers
- list name and
suburb arranged so that suburb is reverse alphabetical
- list name and
number of OLDER siblings of all students in descending order of number
OLDER of siblings
Grouping
- list all sids
grouped by sport
- list all names
grouped by suburb
- list distinct
subjects and the number of students studying each
- list distinct
hobbies and the number of students in each
- list year levels
and the number in each
Some Extension
- List those people
that admit to sharing at least one hobby with yourself
- List the names
of people that don't play sports
- List the house
with the largest number of year 11 students represented.
- List the house
with the second largest number of year 11's represented.
- List the computer
chip type of students that study Economics, play rugby and are from
Windsor house.
The Nasties
- List the names
of those students that enjoy more hobbies than play sports
- derive the number
of people that come from the suburb that has the most people coming
from it
- derive how many
more students do the most done subject when compares with the second
most done subject
- list all middle
born children (of odd numsib families)
solutions