我希望将以下查询用作层次结构查询,即使时间戳有所不同,也不会在作业ID和作业描述中进行任何重复
例如,在以下字段job_id
和job_description
中使用min和max函数,应该只显示一个exec_start_time
,exec_end_time
,没有任何重复。 sol_id
表中的tbaadm.bjm
应该与表set_id
中的tbaadm.sst
映射。
原始查询:
Select Sol_Id,
Job_Id,
Job_Desc,
To_Char(Exec_Start_Time,'HH:MM:SS'),
To_char(Exec_End_Time,'HH:MM:SS'),
Job_Status
From Tbaadm.Bjm
Where Job_Exec_Date = '21-10-2016'
And Job_Desc Like 'SDP%'
Order By Job_Id;
然后我被困住了
Select Sol_Id,
Job_Id,
Job_Desc,
Min(V_Exec_Start_Time),
Max(V_Exec_End_Time),
Job_Status
From (Select Sol_Id,
Job_Id,
Job_Desc,
(To_Char(Exec_Start_Time,'HH:MM:SS')) As v_exec_start_time,
(To_Char(Exec_End_Time,'HH:MM:SS')) As v_exec_end_time,
Job_Status
From Tbaadm.Bjm
Where Sol_Id In (Select Sol_Id From Tbaadm.Sst Where Set_Id = '100')
And Job_Exec_Date = '21-OCT-2016'
And Job_Desc Like 'SDP%')
Group By Sol_Id,Job_Id,Job_Desc,V_Exec_Start_Time,V_Exec_End_Time,Job_Status
Order By Job_Id;
答案 0 :(得分:1)
如果您只想为每项工作写一行,那么就不称为“层次结构”,因为层次结构意味着存在某种父子关系,并且您希望以表格格式显示树状数据。
在这里,您可以简单地按功能使用分组,以便对在必填字段(Exec_Start_Time,Exec_End_Time)上应用了“最小和最大功能”的每个作业获得一行。
谢谢, Jayati