[FYI, this is not homework — I guess everyone thinks that because I made an effort to format my question in a simple readable form? Again, not homework. I’m at work, and just trying to learn. Thanks.]
I’m very stuck on a tricky one. I’m a Java guy, I’m not a SQL guy, so any help with this is GREATLY appreciated!
I have a PROJECT table and a TASK table like so:
**PROJECT**
projectId
name
PROJECT has many TASKs:
**TASK**
taskId
projectId
description
userId // the user who is assigned the task
status // either "IN_PROGRESS" or "COMPLETE"
sequence // the numeric sequence of the TASK in the PROJECT
For example:
Project
projectId=100
name="Build House"
Task
taskId=250 // task IDs are not necessary in numerical order
sequence=1
description="Pour Foundation"
userId=55
status="COMPLETE"
Task
taskId=240
sequence=2
description="Build walls"
userId=56
status="COMPLETE"
Task
taskId=260
sequence=3
description="Install windows"
userId=57
status="IN_PROGRESS"
Task
taskId=245
sequence=4
description="Build roof"
userId=58
status="IN_PROGRESS"
I need two queries:
(1) For a given projectId, get the ‘current task’. The current task is the task number with the smallest sequence number which is not complete. In my example, getCurrentTask(projectId=100) would return taskId 260 (because it’s the first one that is incomplete).
(2) For a given userId, get the list of projects where he is assigned to a ‘current task’. In my example, getProjectsForUserId(userId=57) would return projectId 100; getProjectsForUserId(userId=58) would return nothing.
EDIT
The queries below order by sequence, instead of TaskID.