473,426 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,426 software developers and data experts.

How to convert sql to relational algebra?

Now I have a sql needed to be converted to relational algebra. There are two tables: student and sc.
student has sno, sname, sage.
sc has sno, cno, grade.
How to translate the sql into relational algebra:
select sname from student where sage > 20 or sno in (select sno from sc where grade > 90);

I know it can be converted to union opertaion, but that is too complicated for many sqls like this. Are there any other methods?
I have a plan of sql server, but I could not understand what it means?
Any help with this would be great.
Attached Images
File Type: jpg 截图00.jpg (16.1 KB, 576 views)
Sep 8 '10 #1
3 7869
NeoPa
32,556 Expert Mod 16PB
I'm not sure what you're actually asking as I have no idea what SC might refer to as a table and I haven't come across the term Relational Algebra. That said you may be looking for something like :
Expand|Select|Wrap|Line Numbers
  1. SELECT   tS.SNo
  2.        , [SName]
  3. FROM     [Student] AS tS
  4.          LEFT OUTER JOIN
  5.          [SC]
  6.   ON     tS.SNo = SC.SNo
  7. WHERE   (tS.SAge > 20)
  8.    OR   (MAX(SC.Grade) > 90)
  9. GROUP BY tS.SNo
Sep 8 '10 #2
First thank you very much for you reply.
I have unload a picture about the relational algebra.
In fact, there are three tables: student, sc, course.
course has cno and cname, respectively representing the number and name of course. sc has sno, cno, grade, respectlively representing number of student, number of course and the score.
What I mean is this:
Expand|Select|Wrap|Line Numbers
  1. select sname 
  2.       from student 
  3.       where sage > 20 or 
  4.             sno in (select sno from sc where grade > 90)
It is equal to:
Expand|Select|Wrap|Line Numbers
  1.      select sname from student where sage > 20
  2.      union
  3.      select sname from student 
  4.        where sno in (select sno from sc where grade > 90)
  5.  
Can it be expressed as like this:
Expand|Select|Wrap|Line Numbers
  1.     select sname 
  2.     from student,(select sno from sc where grade > 90) ta
  3.     where sage > 20 or student.sno = ta.sno
  4.  
Maybe there has exists predicate:
Expand|Select|Wrap|Line Numbers
  1.    select sname from student
  2.    where sage > 20 or
  3.          sno in (select sno from sc where grade > 90) or
  4.          exists (select * from course)
  5.  
I don't care what the sqls means, but I only care how the sqls are translated to relational algebra.
Sep 9 '10 #3
Stewart Ross
2,545 Expert Mod 2GB
Hi Saltedfish. What you ask is related to a course assignment and is beyond what we can assist you with. We normally deal with expressing queries in Structured Query Language form, not in reverse-engineering these back to an academic form of logic such as relational algebra (see http://en.wikipedia.org/wiki/Relational_algebra).

I studied predicate calculus many years ago, but even so I don't think this forum is the place for what you are asking. You are asking us to take a SQL-based implementation of relationships between tables and convert that back to its relational algebra equivalent.

Even if we were experts on this - and I for one am not - we cannot do your work for you when it comes to academic coursework.

-Stewart
Sep 9 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: | last post by:
I need to write a relational algebra query for the following: Show the item_ID, item description and category description for all items where the supplier uses "rail" as the delivery_method. ...
2
by: trippedwire | last post by:
i have entity sets account(account-number, balance) branch(branch-name, branch-city, assets) customer(customer-name, customer-street, customer-city) loan(loan-number, amount) and relationship...
0
by: Vishy8015 | last post by:
Use Relational Algebra to express the following queries on the schema FLIGHTS (DepartureCity, ArrivalCity). A pair of cities a, b is in an instance of relation FLIGHTS if there is a direct flight...
0
by: scorpiomailin | last post by:
Hello Guys... thanks in advance jst wondering if any1 knows answer to this.... if this is the SQL query Author(name, hometown, publisher) Textbook(tname, aname, price) select A.name, publisher...
1
by: lava4112 | last post by:
Have a test on SQL, only teacher wants to know what type of relational algebra is a select, where, from--I have no idea and can not understand the teacher. We are using Concepts of Database...
1
by: salman malik | last post by:
software for relational algebra.
2
by: aiom | last post by:
following are the given set of relations : STUDENT(SSN,Name,Major,Bdate) COURSE(Course#,CName,Dept) EnrollCourse#,Quarter,Grade) BOOK_ADOPTION(Course#,Quarter,Book_ISBN)...
1
by: muniba | last post by:
Relational algebric expression for the following: Draw two relational algebra query trees for the following query and show that one query tree is more eficient than the other. "Give the number...
3
Metallicat
by: Metallicat | last post by:
I have been posed and attempted to answer several questions but I do not seem to be getting anywhere. I have emailed my tutor a week ago and he has not responded, If anyone can take a look and help...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.