【发布时间】:2023-02-03 12:38:21
【问题描述】:
我需要每小时对一个表运行一次查询,该表连接和聚合来自另一个具有数百万行的表的数据。
select f.master_con,
s.containers
from
(
select master_con
from shipped
where start_time >= a and start_time <= a+1
) f,
(
select master_con,
count(distinct container) as containers
from picked
) s
where f.master_con = s.master_con
上面的这个查询是有效的,确切的语法可能不正确,因为我是凭记忆写的。
在子查询 's' 中,我只想计算 'f' 查询中每个 master_con 的容器,我认为我的查询运行了很长时间,因为我正在计算所有 master_con 的容器,但随后仅从 ' F'
有没有更好、更有效的方法来编写这种类型的查询?
(最后,我将从上面的这个查询中求和(容器)以获得那个小时内运送的总容器)
【问题讨论】: