count(*) 不 return 0
count(*) doesn't return 0
我有一个 sql 问题,请帮助我,这是我的查询
select count(category_value .list_value_id) as jobs , category_type.value as category
from list_values category_type
full outer join params category_value
on category_type.list_value_id = category_value .list_value_id
join qrtz_triggers jobs
on category_value .object_id = jobs.job_name
and jobs.trigger_state ='PAUSED'
and category_value.attr_id = 9158075153713931109
where category_type.attr_type_def_id = 9158075154713931109
group by category_type.value;
attr_id 是列表值,其中包含 9158075158713931109(非关键)和 9158075157713931109(关键)
returns result:
JOBS, CATEGORY
2 Non-Critical
expected result is :
JOBS, CATEGORY
2 Non-Critical
0 Critical
list_values table conains
list_value_id values
9158075158713931109 non-critical
9158075157713931109 critical
params table
list_value_id attr_id object_id
9158075158713931109 9158075153713931109 a
9158075157713931109 9158075153713931109 b
9158075157713931109 9158075153713931109 c
9158075158713931109 9158075153713931109 d
qtz_trigger table i need triggers with state "paused"
job_name trigger_state
b paused
a paused
e normal
c paused
我什至尝试了 category_value .object_id in (select jobs.job_name from qrtz_triggers jobs where jobs.trigger_type ='SIMPLE') 但收到错误命令未正确结束
本次过滤条件:
where category_type.attr_type_def_id = 9158075154713931109
将把 full join
变成左连接或右连接。
使用 full join
s 过滤非常棘手。我不确定是否需要 full join
- 你的问题并没有解释你真正想做什么。但是,如果您确实需要 full join
,我发现在子查询中进行过滤通常可以满足我的要求。
我认为你实际上想要 left join
s,从 list_values
table 开始,然后加入 params
和 qrtz_triggers
:
select count(t.job_name) as jobs, v.value as category
from list_values v
left join params p
on p.list_value_id = v.list_value_id
and p.attr_id = v.attr_type_def_id
left join qrtz_triggers t
on t.job_name = p.object_id
and t.trigger_state = 'PAUSED'
where v.attr_type_def_id = 9158075154713931109
group by v.value;
原始查询中的条件有点混乱,所以我尝试 re-arrange - 您可能需要查看它。我还使用了简短且具有代表性的 table 别名。
我有一个 sql 问题,请帮助我,这是我的查询
select count(category_value .list_value_id) as jobs , category_type.value as category
from list_values category_type
full outer join params category_value
on category_type.list_value_id = category_value .list_value_id
join qrtz_triggers jobs
on category_value .object_id = jobs.job_name
and jobs.trigger_state ='PAUSED'
and category_value.attr_id = 9158075153713931109
where category_type.attr_type_def_id = 9158075154713931109
group by category_type.value;
attr_id 是列表值,其中包含 9158075158713931109(非关键)和 9158075157713931109(关键)
returns result:
JOBS, CATEGORY
2 Non-Critical
expected result is :
JOBS, CATEGORY
2 Non-Critical
0 Critical
list_values table conains
list_value_id values
9158075158713931109 non-critical
9158075157713931109 critical
params table
list_value_id attr_id object_id
9158075158713931109 9158075153713931109 a
9158075157713931109 9158075153713931109 b
9158075157713931109 9158075153713931109 c
9158075158713931109 9158075153713931109 d
qtz_trigger table i need triggers with state "paused"
job_name trigger_state
b paused
a paused
e normal
c paused
我什至尝试了 category_value .object_id in (select jobs.job_name from qrtz_triggers jobs where jobs.trigger_type ='SIMPLE') 但收到错误命令未正确结束
本次过滤条件:
where category_type.attr_type_def_id = 9158075154713931109
将把 full join
变成左连接或右连接。
使用 full join
s 过滤非常棘手。我不确定是否需要 full join
- 你的问题并没有解释你真正想做什么。但是,如果您确实需要 full join
,我发现在子查询中进行过滤通常可以满足我的要求。
我认为你实际上想要 left join
s,从 list_values
table 开始,然后加入 params
和 qrtz_triggers
:
select count(t.job_name) as jobs, v.value as category
from list_values v
left join params p
on p.list_value_id = v.list_value_id
and p.attr_id = v.attr_type_def_id
left join qrtz_triggers t
on t.job_name = p.object_id
and t.trigger_state = 'PAUSED'
where v.attr_type_def_id = 9158075154713931109
group by v.value;
原始查询中的条件有点混乱,所以我尝试 re-arrange - 您可能需要查看它。我还使用了简短且具有代表性的 table 别名。