如果 where 条件位于连接表上,我会得到重复的结果吗?
我有三个表,一个是任务,是工厂工人分批完成的任务,另一个表,每个任务有一个batch_id,多个任务可以有相同的batch_id。第三个表是batch_log,其中某人处理批次的所有时间都以唯一id、batch_id、该人的用户id、start_time 和end_time 的形式记录。
每个任务都有一个以秒为单位的estimated_recurring 时间和一个以秒为单位的estimated_nonrecurring 时间。我希望获得按操作 ID 分组的这两个字段的总和,操作 ID 是任务表中的一个字段,用于表示是否是激光切割、去毛刺、喷漆等任务。
问题是我只想要在某个时间段内批次日志中包含批次的任务。批次在batch_log 表中具有多个条目。
这是我正在尝试的:
SELECT
operation_id, SUM(t.estimated_nonrecurring + t.estimated_recurring) / 3600 as work_completed
FROM tasks t
INNER JOIN batch_log l on t.batch_id = l.batch_id
WHERE
l.start_time BETWEEN DATE("10:00:00") AND DATE(NOW())
AND
l.time_elapsed < "10:00:00"
GROUP BY t.operation_id
我担心我会得到比实际更高的估计,因为任务表中的多个条目可以具有相同的批次。
I have three tables, one is tasks which are tasks that factory workers complete by putting them into batches, which is another table, each task has a batch_id, multiple tasks can have the same batch_id. The third table is the batch_log where all time that someone has worked on a batch is recorded in the form of a unique id, a batch_id, the person's userid, the start_time and the end_time.
Each task has an estimated_recurring time in seconds and an estimated_nonrecurring time in seconds. I'm looking to get the sum of both of those fields grouped by the operation_id which is a field in the tasks table to represent whether it is a laser cutting, deburr, painting, etc task.
The issue is that I only want the tasks that have batches that were in the batch_log during a time_period. Batches have multiple entries in the batch_log table.
Here is what I'm trying:
SELECT
operation_id, SUM(t.estimated_nonrecurring + t.estimated_recurring) / 3600 as work_completed
FROM tasks t
INNER JOIN batch_log l on t.batch_id = l.batch_id
WHERE
l.start_time BETWEEN DATE("10:00:00") AND DATE(NOW())
AND
l.time_elapsed < "10:00:00"
GROUP BY t.operation_id
I'm concerned that I will get a higher estimate than is real because multiple entries in the task table can have the same batch.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为您只需要基于批处理日志文件中的任务的时间,所以您发布的内容肯定不起作用。
假设您有 3 个表:Tasks、Batches 和 BatchLog。
你会想要这个:
Because you only want the times based on tasks that were in your batch log file what you posted will definately not work.
Assuming you have 3 tables: Tasks, Batches, and BatchLog.
You'll want this: