Netball case study Harryanto Surjani. domain Team names Team locations – where they’re based...

14
Netball case study Harryanto Surjani

Transcript of Netball case study Harryanto Surjani. domain Team names Team locations – where they’re based...

Page 1: Netball case study Harryanto Surjani. domain Team names Team locations – where they’re based Game venues – Venue name and what the stadium is called Draw.

Netball case study

Harryanto Surjani

Page 2: Netball case study Harryanto Surjani. domain Team names Team locations – where they’re based Game venues – Venue name and what the stadium is called Draw.

domain

• Team names• Team locations – where they’re based• Game venues – Venue name and what the

stadium is called• Draw – who’s playing who and in what rounds• Games played – games played so far

Page 3: Netball case study Harryanto Surjani. domain Team names Team locations – where they’re based Game venues – Venue name and what the stadium is called Draw.

erd

Page 4: Netball case study Harryanto Surjani. domain Team names Team locations – where they’re based Game venues – Venue name and what the stadium is called Draw.

1 to M cityid | city--------+------------ 1 | Canberra 2 | Melbourne 3 | Hobart

venueid | cityid | stagename---------+--------+-------------------------------------------- 1 | 1 | AIS Arena 2 | 1 | Subway ACT Netball Centre 3 | 2 | State Netball Hockey Centre

Page 5: Netball case study Harryanto Surjani. domain Team names Team locations – where they’re based Game venues – Venue name and what the stadium is called Draw.

M:M

teamid | cityid | teamname--------+--------+----------------------- 1 | 1 | Canberra Darters 2 | 2 | Melbourne Kestrels 3 | 2 | Melbourne Phoenix

drawid | hometeamid | awayteamid | venueid | round--------+------------+------------+---------+------- 1 | 2 | 3 | 4 | 1 2 | 7 | 1 | 11 | 1 3 | 8 | 5 | 12 | 1

Page 6: Netball case study Harryanto Surjani. domain Team names Team locations – where they’re based Game venues – Venue name and what the stadium is called Draw.

simple queryselect * from hsteam;

teamid | cityid | teamname--------+--------+----------------------- 1 | 1 | Canberra Darters 2 | 2 | Melbourne Kestrels 3 | 2 | Melbourne Phoenix 4 | 4 | Hunter Jaegers 5 | 5 | Adelaide Thunderbirds 6 | 6 | Perth Orioles 7 | 7 | Queensland Firebirds 8 | 9 | Sydney Swift

Shows all rows in the hsteam table.

Page 7: Netball case study Harryanto Surjani. domain Team names Team locations – where they’re based Game venues – Venue name and what the stadium is called Draw.

natural joinselect * from hsteam natural join hscity;

cityid | teamid | teamname | city--------+--------+-----------------------+----------- 1 | 1 | Canberra Darters | Canberra 2 | 2 | Melbourne Kestrels | Melbourne 2 | 3 | Melbourne Phoenix | Melbourne 4 | 4 | Hunter Jaegers | Newcastle 5 | 5 | Adelaide Thunderbirds | Sydney 6 | 6 | Perth Orioles | Perth 7 | 7 | Queensland Firebirds | Brisbane 9 | 8 | Sydney Swift | Adelaide

Shows which city each team is based in.

Page 8: Netball case study Harryanto Surjani. domain Team names Team locations – where they’re based Game venues – Venue name and what the stadium is called Draw.

cross productselect * from hsteam, hscity where hsteam.cityid = hscity.cityid;

teamid | cityid | teamname | cityid | city--------+--------+-----------------------+--------+----------- 1 | 1 | Canberra Darters | 1 | Canberra 2 | 2 | Melbourne Kestrels | 2 | Melbourne 3 | 2 | Melbourne Phoenix | 2 | Melbourne 4 | 4 | Hunter Jaegers | 4 | Newcastle 5 | 5 | Adelaide Thunderbirds | 5 | Sydney 6 | 6 | Perth Orioles | 6 | Perth 7 | 7 | Queensland Firebirds | 7 | Brisbane 8 | 9 | Sydney Swift | 9 | Adelaide

Shows which city each team is based in.

Page 9: Netball case study Harryanto Surjani. domain Team names Team locations – where they’re based Game venues – Venue name and what the stadium is called Draw.

group byselect teamname, count(*) as home_games

from hsdraw natural join hsteam

where hometeamid = teamid

group by teamname;

teamname | home_games

-----------------------+------------

Melbourne Phoenix | 7

Perth Orioles | 7

Adelaide Thunderbirds | 7

Hunter Jaegers | 7

Melbourne Kestrels | 7

Queensland Firebirds | 7

Canberra Darters | 7

Sydney Swift | 7

Shows how many home games each team has.

Page 10: Netball case study Harryanto Surjani. domain Team names Team locations – where they’re based Game venues – Venue name and what the stadium is called Draw.

subqueryselect teamname, awaypoints, homepoints

from hsdraw natural join hsgame, hsteam

where awayteamid=teamid and

awaypoints >= (select max(homepoints) from hsgame);

teamname | awaypoints | homepoints

-----------------------+------------+------------

Adelaide Thunderbirds | 69 | 40

Shows the most points an away team has had over a home team.

Page 11: Netball case study Harryanto Surjani. domain Team names Team locations – where they’re based Game venues – Venue name and what the stadium is called Draw.

cross productselect home.teamname as home_teamname, away.teamname as away_teamname from hsdraw, hsgame, hsteam home, hsteam away where hsdraw.hometeamid = home.teamid and hsdraw.awayteamid=away.teamid and homepoints > awaypoints and round = 1 and hsgame.drawid=hsdraw.drawid;

home teamname | away teamname----------------------+----------------------- Queensland Firebirds | Canberra Darters Sydney Swift | Adelaide Thunderbirds Hunter Jaegers | Perth Orioles

Shows the home teams that won in round 1.

Page 12: Netball case study Harryanto Surjani. domain Team names Team locations – where they’re based Game venues – Venue name and what the stadium is called Draw.

constraints

constraint check_hshomepoints check (homepoints > 0),

constraint check_hsawaypoints check (awaypoints > 0)

constraint validhscity check

(city in ('Canberra', 'Melbourne', 'Hobart', 'Newcastle',

'Sydney', 'Perth', 'Brisbane', 'Wollongong',

'Adelaide', 'Grafton'))

Page 13: Netball case study Harryanto Surjani. domain Team names Team locations – where they’re based Game venues – Venue name and what the stadium is called Draw.

delete cascadesconstraint fkhscityid foreign key (cityid) references

hscity (cityid)

on update cascade

on delete cascade

constraint fkhshometeamid foreign key (hometeamid) references hsteam (teamid)

on delete cascade

on update cascade,

constraint fkhsawayteamid foreign key (awayteamid) references hsteam (teamid)

on delete cascade

on update cascade,

Page 14: Netball case study Harryanto Surjani. domain Team names Team locations – where they’re based Game venues – Venue name and what the stadium is called Draw.

viewsCREATE view hshomepointstable (team, points)

as select teamname, count(*)*2

from hsgame natural join hsdraw, hsteam

where homepoints > awaypoints and hometeamid = teamid

group by teamname;

CREATE view hsawaypointstable (team, points)

as select teamname, count(*)*2

from hsgame natural join hsdraw, hsteam

where awaypoints > homepoints and awayteamid=teamid

group by teamname;

CREATE view hspointstable (team, points)

as select team,

CASE WHEN home.points is null THEN away.points

WHEN away.points is null then home.points

ELSE home.points+away.points

END

from hshomepointstable home FULL JOIN hsawaypointstable away

using (team);