SQL关系
我有四个表:
- 任务 - 有一个batch_id以及完成任务需要多长时间的估计
- - 任务组
- batch_log - 显示每个任务的工作时间以及工作人员的用户ID的条目。
- 操作 - 运行批次的机器类型,油漆,丝网印刷等。
我如何让每个批次为每个用户工作,这些批次 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 中使用这些查询。我想我可能必须进行两个查询:
- 批处理日志
- 查询以获取每批的总估计值
I have four tables:
- task - have a batch_id and estimates of how long a task would take to complete
- batches - groups of tasks
- batch_log - entries showing the time worked for each task with a userid for who worked it.
- 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:
- the batch log
- a query to get the total estimated for each batch
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
类似于:
如果没有任何类型的表结构可供参考,很难说。
Something like:
Hard to say without any sort of table structure to go by.
我不确定你的表的结构,但这样的东西应该有效:
I'm not sure on the structure of your tables, but something like this should work:
从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 ?