-3

Consider the following relational database schemes:

COURSES (Cno,name)
PRE-REQ(Cno, pre-Cno)
COMPLETED (student_no, Cno)

COURSES gives the number and name of all the available courses.

PRE-REQ gives the information about which courses are pre-requisites for a given course.

COMPLETED indicates what courses have been completed by students

Express the following using relational algebra:

List all the courses for which a student with student_no = 2310 has completed all the pre-requisites.

the question can be solved by SQL query but unable to derive equivalent relational algebra.

  • 1
    I'm voting to close this question as off-topic because it's not related to software development and is homework question with no effort put into solving it. – EpicPandaForce Jul 28 '17 at 17:39
  • i have attempted it using division operator(%) but it ii not correct. – Shashank Rao Jul 28 '17 at 19:09
  • 1
    So you could give the SQL you have used; and what you've tried with division; and explain why it's not correct. That would show how much effort you have put in. Perhaps @EpicPandaForce would prefer that Relational Algebra questions go to cs.stackexchange? – AntC Jul 29 '17 at 11:46
  • @AntC well it *is* more suitable for there than on SO. Keep in mind that initially the question only contained the task to solve, kinda like straight out of a test assignment. – EpicPandaForce Jul 29 '17 at 12:47
  • SELECT cno FROM Completed, Pre-Req WHERE student_no = '2310' GROUP BY cno HAVING pre-Cno IN ( SELECT C.cno FROM Completed AS C WHERE C.student_no = '2310'; ) – Shashank Rao Aug 10 '17 at 01:58
  • Please edit clarifications into your question, with proper explanation, not into comments. We are not here to do your homework. Ask a question where we help you get unstuck on one thing, and explain what you think you are doing so we can correct or inform you. Give a reference to what "relational algebra" you are to use--there are many. – philipxy Aug 13 '17 at 21:27

2 Answers2

0

Here's an answer in the TUTORIAL D variant of RA:

WITH { COMPL_2310 := (COMPLETED WHERE student_no = '2310')
                      { Cno } RENAME { Cno AS pre-Cno }
     }
COURSES WHERE ( ( RELATION{ TUPLE{*} } JOIN PRE_REQ ){ pre-Cno }
              ⊆
                COMPL_2310
              )

(This uses some of the recently introduced syntactic sugar and alternative syntax compared to Date & Darwen's textbooks.)

AntC
  • 2,623
  • 1
  • 13
  • 20
0

this may be the correct answer

ΠCno(PRE-REQ) - ΠCno( PRE-REQ - (COMPLETED ⋈COMPLETED.Cno=pre-Cno ^ student_no=2310 PRE-REQ ))

  • Why might it? Why not? This query is invalid because `-` requires that the argument column sets be the same. – philipxy Aug 13 '17 at 21:32
  • both have same column set i.e {Cno} – Shashank Rao Aug 15 '17 at 03:49
  • The second `-`. Please address my comment on the question. 3404097 Eg Since you haven't given a reference the RA you are to use, we don't know the columns of the rightmost join result for sure. But they're different from PRE-REQ's. And we don't know what operators we can use. Or even what a "relation" is. PS https://stackoverflow.com/a/44411096/3404097 https://stackoverflow.com/a/24425914/ – philipxy Aug 15 '17 at 04:00