Relational Algebra: Basic Operators Projection (): id, name - - PowerPoint PPT Presentation

relational algebra basic operators
SMART_READER_LITE
LIVE PREVIEW

Relational Algebra: Basic Operators Projection (): id, name - - PowerPoint PPT Presentation

Relational Algebra: Basic Operators Projection (): id, name (Students) SELECT id, name FROM <SQL for Students> Selection (): id = 100 (Students) SELECT * FROM <SQL for Students> WHERE id = 100 Join (


slide-1
SLIDE 1

Relational Algebra: Basic Operators

  • Projection (π):

πid, name(Students) → SELECT id, name FROM <SQL for Students>

  • Selection (σ):

σ id = 100(Students) → SELECT * FROM <SQL for Students> WHERE id = 100

  • Join (⋈):

Students ⋈Student.id = Grades.id Grades → SELECT * FROM <SQL for Students>, <SQL for Grades> WHERE Student.id = Grades.id

slide-2
SLIDE 2
  • Set operations (⋃, ⋂, −): Same as in SQL (UNION, INTERSECT, MINUS)
  • Renaming (⍴):

⍴S(i,n)(Students) → (SELECT id AS i, name AS n FROM Students) AS S

  • Removing duplicates (δ):

δ(R) → SELECT DISTINCT * FROM <SQL for R>

  • Grouping/aggregation (𝛅):

𝛅id, AVG(grade) → average(Grades) → SELECT id, AVG(grade) AS average FROM <SQL for Grades> GROUP BY id

Relational Algebra: More operators

slide-3
SLIDE 3

Relational Algebra: Sanity check

  • Every condition, projection, etc. should ONLY mention attributes that exists in their
  • perands.

Students(idnr, name) Grades(student, course, grade) student -> Students.idnr πname (σpassed>=2 AND idnr=student AND grade>=3 (Students ⋈ γstudent, COUNT(*) → passed

(Grades)))

“Select the students with at least two passed courses with a grade

  • f at least 3”
slide-4
SLIDE 4

Relational Algebra: Sanity check

  • Every condition, projection, etc. should ONLY mention attributes that exists in their
  • perands.

Students(idnr, name) Grades(student, course, grade) student -> Students.idnr πname (σpassed>=2 AND idnr=student AND grade>=3 (Students ⋈ γstudent, COUNT(*) → passed

(Grades)))

Can not use grade here!

“Select the students with at least two passed courses with a grade

  • f at least 3”
slide-5
SLIDE 5

Relational Algebra: Sanity check

  • Every condition, projection, etc. should ONLY mention attributes that exists in their
  • perands.

Students(idnr, name) Grades(student, course, grade) student -> Students.idnr πname (σpassed>=2 AND idnr=student (Students ⋈ γstudent, COUNT(*) → passed

(σgrade>=3(Grades))))

“Select the students with at least two passed courses with a grade

  • f at least 3”

We need to filter by grade before the aggregating our data!