SQL关系

发布于 2024-11-02 10:45:37 字数 929 浏览 5 评论 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. 查询以获取每批的总估计值

I have four tables:

  1. task - have a batch_id and estimates of how long a task would take to complete
  2. batches - groups of tasks
  3. batch_log - entries showing the time worked for each task with a userid for who worked it.
  4. operation - type of machine the batch is run on, paint, silkscreen, etc.

How would I get each batch worked for each user, the total elapsed from each batch log for those batch ids and the total estimate from each task id for that batch?

EDIT:

TABLES:

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

I'm thinking:

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

The reasoning for doing this is so that it can be possible to rate the users on how productive they are and use these queries in excel. I think I may have to go with two queries:

  1. the batch log
  2. a query to get the total estimated for each batch

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

痴意少年 2024-11-09 10:45:37

类似于:

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

如果没有任何类型的表结构可供参考,很难说。

Something like:

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

Hard to say without any sort of table structure to go by.

ヤ经典坏疍 2024-11-09 10:45:37

我不确定你的表的结构,但这样的东西应该有效:

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

I'm not sure on the structure of your tables, but something like this should work:

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
剑心龙吟 2024-11-09 10:45:37

从batch_log中选择不同的bl.userid,t.batchid bl内连接任务t on t.taskid = bl.taskid;

选择 sum(bl.time_spent) , b.batchid 来自批次 b 左连接任务 t 上 b.batchid = t.batchid 内连接 batch_log bl 上 bl.taskid = t.taskid;

从批次 b 中选择 sum(t.estimate) 、 b.batchid 左连接任务 t on b.batchid = t.batchid ;

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

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 ;

Why is it called batch_log but it is about taskes and time spent ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文