0

我有四张桌子:

  1. 任务 - 有一个 batch_id 和估计任务需要多长时间才能完成
  2. 批次 - 任务组
  3. batch_log - 显示每个任务的工作时间的条目,并带有工作人员的用户 ID。
  4. 操作 - 批次运行的机器类型、油漆、丝网印刷等。

我如何让每个用户为每个批次工作,每个批次日志中这些批次 ID 的总时间以及该批次的每个任务 ID 的总估计值?

编辑:

表格:

task
id     estimated_nonrecurring   estimated_recurring  batch_id

batch
id     operation_id date_entered

batch_log
id     userid    batch_id   time_elapsed

operation
id     name

我在想:

get each user;
get a list of distinct batch_ids that they worked on;
get a sum of all the time_elapsed from each batch_log for those batch id;
get all the non_recurring and the recurring for each task with each batch_id;

so that the result is like

userid, operation, batch_id, total_elapsed, total_estimate, date_entered

这样做的原因是可以对用户的工作效率进行评分,并在 Excel 中使用这些查询。我想我可能不得不去两个查询:

  1. 批处理日志
  2. 获取每个批次的总估计值的查询
4

3 回答 3

1

select distinct bl.userid , t.batchid from batch_log bl inner join task t on t.taskid = bl.taskid ;

select sum(bl.time_spent) , b.batchid from batch b left join task t on b.batchid = t.batchid inner join batch_log bl on bl.taskid = t.taskid;

select sum(t.estimate) , b.batchid from batch b left join task t on b.batchid = t.batchid ;

为什么它被称为 batch_log 但它是关于任务和花费的时间?

于 2011-04-19T16:04:43.043 回答
1

我不确定你的表格的结构,但这样的事情应该有效:

select batch.id, 
(select sum(batch.time)
from batch_log 
inner join task on task.id = batch_log.id
where task.batchId = batch.id) as total,
(select sum(task.estimate ) from task where task.batchId = batch.id) as estimate
from batch
inner join task on task.batchId = batch.id
where batch_log.userId = @userId
于 2011-04-19T16:06:50.163 回答
1

就像是:

SELECT bl.UserId, b.name, t.estimate
FROM batch_log as bl
JOIN batches as b
    ON b.id = bl.batch_id
JOIN task as t
    ON t.id = b.task_id
WHERE bl.UserId = 123

很难说没有任何类型的表结构可以通过。

于 2011-04-19T16:08:45.027 回答