【发布时间】:2021-10-27 22:13:57
【问题描述】:
select s1.name,min(s1.start_time),max(s2.end_time),
round(((max(s2.end_time) - min(s1.start_time)))*24)
from My_table s1,My_table s2
where (s1.process in ('abcd') and month like '%1708021%') and
(s2.process in ('xyz' and month like '%1708021%'))
group by s1.process_name;
PROCESS_NAME MIN(S1.START_TIME) MAX(S2.END_TIME) ROUND(((MAX(S2.END_TIME)-MIN(S1.START_TIME))))
alert17 18-aug-2021 07:49:45 PM 20-aug-2021 12:01:09 PM 40
如果我在上面运行查询,我的表中有 31 个条目,我会从中获得正确的数据,即进程 start_time 和 end_time 以及差异。
但如果我在月份级别运行它,那么它会给我错误的数据
select s1.name,min(s1.start_time),max(s2.end_time),
round(((max(s2.end_time) - min(s1.start_time)))*24)
from My_table s1,My_table s2
where (s1.process in ('abcd') and month like '%08021%') and
(s2.process in ('xyz' and month like '%08021%'))
group by s1.process_name;
Alert01 03-aug-2021 01:50:47 AM 27-aug-2021 06:16:30 AM 580
Alert02 03-aug-2021 08:10:57 PM 27-aug-2021 06:16:30 AM 562
Alert03 04-aug-2021 08:07:21 PM 27-aug-2021 06:16:30 AM 538
Alert04 06-aug-2021 03:42:51 AM 27-aug-2021 06:16:30 AM 507
你们能帮帮我吗?
【问题讨论】:
-
很难理解你想要做什么。消除连接并将其替换为聚合函数中的过滤似乎会更清晰、更有效。你只按一列分组,所以我可能猜想连接不是你想要的。
-
@RohanDolas 。 . .我的建议:删除这个问题。问一个新问题。对您要完成的工作提供清晰的解释。提供样本数据和期望的结果。然后显示有效或无效的查询。