A noob to databases looking for a little advice/pointers to get me started.
I need to create a DB to hold the details of a number of users along with a list of tasks which they must complete weekly. This data will then be used to show a table of the users along with the weekly completion status of the jobs. This table should be able to show my previous weeks statuses as well.
The list of jobs must allow new jobs to be added and old ones removed.
I currently have the following tables:
-----
User
-----
ID
Name
Email
A number of users will be entered into this table.
----
Job
----
ID
Name
Description
A list of jobs (starting at 4) which each user has to mark as completed each week, this list must be able to grow.
---------
WorkDone
---------
ID
User_ID
Job_ID
Timestamp
Used to record when a user has marked a job as complete.
Is my table structure okay or am I coming at this from the wrong angle? I need to write a query which will allow me to return:
User.ID (1) | Job 1 completed status | Job 2 completed status | Job (n) completed status
User.ID (2) | Job 1 completed status | Job 2 completed status | Job (n) completed status
User.ID (n) | Job 1 completed status | Job 2 completed status | Job (n) completed status
I’m having no luck here and I’m just looking for that “doh” of course moment.
Any help is appreciated.
if you want the results returned like
userid, job 1 status,job 2 status, job 3 status
userid(2), job 1 status,job 2 status, job 3 status
you will need to pivot the result set, use a cursor, or run try using the coalesce operator.
Getting the data to fit this pattern will be much easier
userid, job1
userid, job2
userid, job3
…
…
userid(2), job1
userid(2), job2
….
the sql for this would be set based and run faster