SQL% 查找任务
SQL percent finding task
我正在尝试获取每种消息的处理错误百分比。
顺便说一句,我们只需要取 > 5% 的百分比。
试图找到解决方案,但没有任何效果..
数据库结构:
QRY_TYPE(ID
– 类型的唯一标识符,С_NAME
– 类型名称,C_AB_REF
– link 处理这些类型消息的 abonent。
ST_ABONENTS(ID
– 唯一标识符,С_NAME
– 姓名)
QRY_QUEUE(ID
– 唯一标识符,С_IN_TIME
– 将消息写入 table 的日期和时间,C_EXEC_TIME
– 消息处理的日期和时间,C_ST
– 处理状态(null - 没有,1 – 成功,0 – 处理错误),C_QRY_TYPE
– link对于查询类型)。
那是我的尝试之一,它仍然不起作用
select qt.c_name as qrytype, count(qq.C_ST)/(SELECT count(*) from qry_queue)*100 as PRC
from qry_type qt
inner join qry_queue qq on qt.id = qq.c_qry_type
where qq.c_st =0
group by qt.c_name;
结果应如下所示
如果没有实际数据和信息,很难说出什么不起作用。
这可能就是您想要的:
select *
from
(
select qt.c_name as qrytype,
count(case when qq.c_st = '0' then qq.C_ST end) -- only rows with errors
/count(*) * 100 as PRC -- all rows
from qry_type qt
inner join qry_queue qq on qt.id = qq.c_qry_type
group by qt.c_name
) dt
where PRC >= 5
我正在尝试获取每种消息的处理错误百分比。 顺便说一句,我们只需要取 > 5% 的百分比。 试图找到解决方案,但没有任何效果..
数据库结构:
QRY_TYPE(ID
– 类型的唯一标识符,С_NAME
– 类型名称,C_AB_REF
– link 处理这些类型消息的 abonent。
ST_ABONENTS(ID
– 唯一标识符,С_NAME
– 姓名)
QRY_QUEUE(ID
– 唯一标识符,С_IN_TIME
– 将消息写入 table 的日期和时间,C_EXEC_TIME
– 消息处理的日期和时间,C_ST
– 处理状态(null - 没有,1 – 成功,0 – 处理错误),C_QRY_TYPE
– link对于查询类型)。
那是我的尝试之一,它仍然不起作用
select qt.c_name as qrytype, count(qq.C_ST)/(SELECT count(*) from qry_queue)*100 as PRC
from qry_type qt
inner join qry_queue qq on qt.id = qq.c_qry_type
where qq.c_st =0
group by qt.c_name;
结果应如下所示
如果没有实际数据和信息,很难说出什么不起作用。
这可能就是您想要的:
select *
from
(
select qt.c_name as qrytype,
count(case when qq.c_st = '0' then qq.C_ST end) -- only rows with errors
/count(*) * 100 as PRC -- all rows
from qry_type qt
inner join qry_queue qq on qt.id = qq.c_qry_type
group by qt.c_name
) dt
where PRC >= 5