a query problem

From: Giovanni Gigante <giov(at)cidoc(dot)iuav(dot)it>
To: pgsql-novice(at)postgresql(dot)org
Subject: a query problem
Date: 2010-03-04 19:15:46
Message-ID: 4B9006E2.2020300@cidoc.iuav.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


Suppose that you have a small database for scheduling and
tracking tasks.

There are four tables:
PERSONS (name)
TASKS (name)
SCHEDULED (date, FK task, FK person)
EXECUTED (date, FK task, FK person)

so the relationships are:
a PERSON has zero or more EXECUTED
a PERSON has zero or more SCHEDULED
a TASK has zero or more EXECUTED
a TASK has zero or more SCHEDULED

now suppose that the database contains these rows:
PERSON ('john')
TASK ('mowing')
TASK ('digging')
TASK ('pruning')
SCHEDULED ('sunday', 'mowing', 'john')
SCHEDULED ('monday', 'digging', 'john')
EXECUTED ('tuesday', 'mowing', 'john')
EXECUTED ('wednesday', 'pruning', 'john')

I need to build a query that produces a list of rows,
in the EXECUTED table, with added the scheduled.day
*if exists*. That is, something like:

executed.day task.name person.name scheduled.day
-----------------------------------------------------
'tuesday' 'mowing' 'john' 'sunday'
'wednesday' 'pruning' 'john' (NULL)

I realize that the problem would be trivial if SCHEDULED and
EXECUTED were a single table. However, I find myself in a
situation like the one described, and altering the database
structure is not possible.
Is there to build such a query in this situation? So far,
I haven't been able to.

Thanks,
Giovanni

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Michael Wood 2010-03-04 21:16:01 Re: a query problem
Previous Message bill house 2010-03-04 04:53:25 Re: Function