Reversing steps, Converting SQL query back to tuple relational calculus?

南笙酒味 提交于 2021-02-09 10:57:37

问题


Not sure it is a correct SQL and would like to work backward converting SQL back to tuple relational calculus to check the correctness. Let's say we come up this query to display the classes where all its requirement classes have been complete by all the participants who finished the introduction. So we have two tables, progress and requirement. where progress: mId (string), cId (string) and requirement: : cId (string), rId (string) all the enrollment are kept in progress and all the requirements are specified requirement table.

mId:memeberId
cId:cId
rId:requirmentClassId



Select cId 
From requirement r 
Where r.rId in (Select distinct(cId) 
                From progress 
                Where mId in (Select mId 
                              From  progress 
                              Where cId='intro'
                               )
                );

We first select all the members from the progress table where they has done the intro session. Select mId From progress Where cId='intro'

Then we have all the members who finished the intro, so we can select all the other distinct classes has done by the members.

Select distinct(cId) 
                From progress 
                Where mId in (Select mId 
                              From  progress 
                              Where cId='intro'
                               )
                )

Now we have all the classes completed by all the members who finished the intro, now we can find out all the next possible class(es) that should be offered to all the members who finish the intro?

Ok, after I finish writing the question, I don't think this query is correct since now we have all the classes completed by all the members who took the intro, but not necessary all the classes is completed by individual student, correct ? Please check my work. any help is highly appreciated.

来源:https://stackoverflow.com/questions/65935372/reversing-steps-converting-sql-query-back-to-tuple-relational-calculus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!