我这个例子,我需要得到基于优先级的工作/任务百分比的列表:聚合函数或GROUP BY子句中嵌套查询复杂
Priority Percentages
-----------------------
1 %25
11 %10
task_events
表:
task_events_id time missing_info job_id task_index machine_id event_type user scheduling_class priority cpu_request memory_request disk_space_request different_machines_restriction
job_id
其任务可以在多行中,所以我创建了新的列task_events_id
作为PK,用于嵌套选择以获取每个作业和任务的信号行。然后应用此结果来获得每项工作的优先级。我想出了这个查询。这里的主要概念是,我有11个优先级。优先考虑有很多工作。每个作业都被分配到一个优先级。
Select
tes.[priority], (tes.total_priority * 100/(select sum(tes.total_priority)from tes)) as [percentage]
From
(select
[priority], count(*) as total_priority
from
task_events as t
inner join
(select
max(task_events_id) as maxid, 1 as total
from
task_events
group by
job_id, task_index) as te on t.task_events_id = te.maxid
group by
[priority]) as tes
group by
tes.[priority]
这最好的我想出了,但总的是越来越复杂,任何建议
与此查询我得到这个错误:
无效的对象名称TES“。
while it's put'tes.total_priority'on last group by。
样本数据和预期的结果将真正帮助解释你想要做什么。例如,百分比是什么? –
每个job_id,这里的每个工作都有优先权,我有11个优先级,每个优先级都有很多工作 – jou