数据库的一个菜鸟,寻找一些建议/指针让我开始。
我需要创建一个数据库来保存许多用户的详细信息以及他们必须每周完成的任务列表。然后,该数据将用于显示用户表以及作业的每周完成状态。此表应该能够显示我之前的周状态。
作业列表必须允许添加新作业并删除旧作业。
我目前有以下表格:
-----
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.
我的桌子结构还可以,还是我从错误的角度来看这个?我需要写一个允许我返回的查询:
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
我在这里没有运气,我只是在寻找那个“doh”当然。
感谢任何帮助。
答案 0 :(得分:0)
如果您希望返回结果,如
用户ID,作业1状态,作业2状态,作业3状态
userid(2),作业1状态,作业2状态,作业3状态
您需要旋转结果集,使用光标或使用coalesce运算符运行尝试。
使数据更适合这种模式将更容易
userid,job1
userid,job2
userid,job3
...
...
userid(2),job1
userid(2),job2
....
用于此的sql将基于设置并且运行得更快
Select *
from join workdone as w
inner join job as j on w.jobid = j.jobid
inner user as u on u.userid = w.userid