Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
400 views
in Technique[技术] by (71.8m points)

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

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.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...