0

私は4つのテーブルを持っています:

  1. task - 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 で使用できるようにするためです。私は2つのクエリを使用する必要があるかもしれないと思います:

  1. バッチログ
  2. 各バッチの推定合計を取得するクエリ
4

3 に答える 3

1

異なる bl.userid 、 t.batchid を batch_log から選択 bl 内部結合タスク 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 に答える