代码正在配置单元上运行:
select day,count(mdn)*5 as number from
(select distinct a.mdn,a.day from
flow a
left outer join
flow b
on a.day=date_add(b.day,-1) and a.mdn=b.mdn
left outer join
flow c
on a.day=date_add(c.day,-2) and a.mdn=c.mdn
left outer join
flow d
on a.day=date_add(d.day,-3) and a.mdn=d.mdn
where b.mdn is null and c.mdn is null and d.mdn is null)t
group by day
代码的逻辑是选择一个今天的mdn,这个mdn在未来三天内没有出现,然后计算mdn的个数,但是这个代码的效率很低,因为使用同一个大表流进行了三次连接。如何高效简化?
1条答案
按热度按时间o0lyfsai1#
好吧,你可以用
lead()
比较日期和时间: