[thelist] Another SQL query

Bill Moseley moseley at hank.org
Wed Sep 12 09:20:52 CDT 2007


I'm hoping someone can help with a query.

I just received this schema that tracks "tasks" with a task table:

    task_id  |  name
  -----------+-----------
       1     |  Task One
       2     |  Task Two

where tasks are actually made up of "task_parts"
that reference the task above:

     part_id  | task_id_fk  | points
   -----------+-------------+---------
        1     |    1        |   22
        2     |    1        |   10
        3     |    1        |   11
        4     |    2        |   23
        5     |    2        |   13

So task one has three parts and task two has two parts.

The task_parts are processed together as a group.  That is, when a
task is processed all of its parts are processed to complete the task.
A task can be processed more than one time.


That completed task parts are recorded in a log table.

     log_id  |  task_part_fk | start_time | end_time
   ----------+---------------+------------+----------
        1    |       1       |  ......    | ......
        2    |       3       |  ......    | ......
        3    |       2       |  ......    | ......
        4    |       4       |  ......    | ......
        5    |       5       |  ......    | ......
        6    |       3       |  ......    | ......
        7    |       2       |  ......    | ......
        8    |       1       |  ......    | ......

So, in this log "Task One" (parts 1,2,3) was processed two times and
"Task Two" (parts 4,5)  was only processed once.  The start and end
times just reflect when the individual part was processed so is not
really important, and you can see that the parts are not processed in
any order.


Here's where I'm stuck:

I need two numbers, but I'm not sure I have enough info.  I need to
know:

 1) how many unique tasks have been processed (which is only 2 in this
 case)

 2) how many tasks have been processed total (which is 3)



Thanks,



-- 
Bill Moseley
moseley at hank.org




More information about the thelist mailing list