2

I have these two "tables":

Station (station_id, city)            // Stations details
Rainfall (station_id, date, amount)   // Rainfall measurements

With Tuple Relational Calculus (TRC), I need to get the IDs of all stations that have related measurements on every date in which any measurement was taken.

So with the following tables I'm supposed to select 5 because this station has measurements on every date that has a measurement.

       Station                             Rainfall
       -------                             --------
--station_id-----city--      --station_id-----date-----amount--
      5           LA               5          01/01      4
      7           NY               7          02/02      8
                                   5          02/02      3

I've tried this but I'm not quite sure if this would work if there are no measurements at all (in this case I'm supposed to select all station IDs):

{ t | ∃s ∈ Station (t[station_id] = s[station_id] ∧ 
    ∀r ∈ Rainfall (∃q ∈ Rainfall (r[date] = q[date] ∧ s[station_id] = q[station_id])) ) }

I need your help in understanding if what I did is correct.

3

I had to look up wikipedia because I did not know Tuple Relational Calculus. I did only skim over that article. There are differnces in notation as far as I can see.

But after activating my knowledge about formal logic I think you are right because

∀r ∈ Rainfall (...)

is true if Rainfall does not contain any tuples. In this case your query reduces to

{ t | ∃s ∈ Station (t[station_id] = s[station_id]}

and this describes all tuples of Station

What I am missing in your notation is that is unclear which attributes the tuple t of the solution contains. So if you want to select station_id then the query should start with something like

{ t: {station_id} | ...}

if one uses the notataion of the wiki article.

Maybe you can supply some reference to your notation.

  • This is a minor topic on a course I'm taking in my university, and unfortunately the only reference I have for this notation is an unclear presentation in my native language. They use t as some kind of a "magic variable" that you can use as you wish... – Itay May 6 '14 at 7:05
  • 2
    if you say "I need to get the IDs of (...) stations.." this should be somewhere expressed in the query. If you change your problem text to "I need to get the IDs and cities of (...) stations..." this will result in exactly the same query if one uses your notation. But of course nothing changes in the solution formula after the |. – miracle173 May 6 '14 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.