If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > A Relational Algebra Question: Combination of RENAME and WHERE

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-16-10, 03:27
horizon horizon is offline
Registered User
 
Join Date: Dec 2010
Posts: 1
A Relational Algebra Question: Combination of RENAME and WHERE

Hi everyone.

The question is about an expression in the Date's book (8th edition, page 199):

Code:
EXTEND S
ADD COUNT ((SP RENAME S# AS X) WHERE X = S#)
AS NP
and specially the part: "COUNT ((SP RENAME S# AS X) WHERE X = S#)"

How this calculates the number of shipments for each supplier separately?
I think the condition X = S# is true for all rows, and the COUNT function should count all rows, unless it resets to 0 each time!

Thank you all for any comment.
Reply With Quote
  #2 (permalink)  
Old 12-17-10, 06:28
dportas dportas is offline
Registered User
 
Join Date: Dec 2007
Location: London, UK
Posts: 732
The point of EXTEND is that the COUNT part behaves like a correlated subquery - it gets computed for each tuple in S. The supplier number is renamed as X in SP, so the WHERE expression means X (in SP) = S# (in S).

Did you try it out yourself? Rel (Rel) includes the scripts to create the supplier and parts relvars and the sample data.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On