select 项目, sum(中位数时间差) as 中位数时间差, sum(百分之九十时间差) as 百分之九十时间差,sum(标本数) as 标本数 from (
select 项目, sum(中位数时间差) 中位数时间差,null 百分之九十时间差, null 标本数 from (
select distinct 项目,中位数,(sum(中位数时间差)/2) 中位数时间差, null 百分之九十时间差, null 标本数 from (
select 项目,中位数,中位数时间差, null 百分之九十时间差, null 标本数 from (
select case 奇数 when 1 then trunc((标本数+1)/2) else (标本数/2) end 中位数,项目 from (
--+标本数/2+1)/2)
select count(a.id) as 标本数,
mod(count(a.id),2) 奇数,
d.名称 as 项目
from 检验报告记录 a, 检验申请组合 b, 检验组合项目 c, 诊疗项目目录 d
where a.id = b.标本id
and b.紧急 = /*B2*/'0'/*E2*/
and b.申请时间 between /*B0*/TO_DATE('2024-04-10 00:00:00','YYYY-MM-DD HH24:MI:SS')/*E0*/
and /*B1*/TO_DATE('2024-04-10 23:59:59','YYYY-MM-DD HH24:MI:SS')/*E1*/
and b.组合id = c.id
and c.诊疗编码 = d.编码
and d.id in(1085,1075,6024,1092,8018,1058,1077,8914,4822,8015,1166,1081,32188,32003,17498,17499)
and b.病人来源=1
and a.采样时间 is not null
and a.审核时间 is not null
group by d.名称
)) A,( select row_number() over(partition by 名称 order by 中位数时间差 ) 序号,中位数时间差,名称 from (
select
-- round(TO_NUMBER((a.采样时间-b.申请时间) * 24 * 60), 1) 中位数时间差,
trunc(((a.审核时间-a.采样时间) * 24 * 60)) 中位数时间差,
d.名称
from 检验报告记录 a, 检验申请组合 b, 检验组合项目 c, 诊疗项目目录 d
where a.id = b.标本id
and b.紧急 = /*B2*/'0'/*E2*/
and b.申请时间 between /*B0*/TO_DATE('2024-04-10 00:00:00','YYYY-MM-DD HH24:MI:SS')/*E0*/
and /*B1*/TO_DATE('2024-04-10 23:59:59','YYYY-MM-DD HH24:MI:SS')/*E1*/
and b.组合id = c.id
and c.诊疗编码 = d.编码
and d.id in(1085,1075,6024,1092,8018,1058,1077,8914,4822,8015,1166,1081,32188,32003,17498,17499)
and b.病人来源=1
and a.采样时间 is not null
and a.审核时间 is not null
order by 中位数时间差 desc ) ) b where a.中位数=b.序号 and a.项目=b.名称
union all
select 项目,中位数,中位数时间差, null 百分之九十时间差, null 标本数 from (
select case 奇数 when 1 then trunc((标本数+1)/2) else (标本数/2+1) end 中位数,项目 from (
--+标本数/2+1)/2)
--偶数
select count(a.id) as 标本数,
mod(count(a.id),2) 奇数,
d.名称 as 项目
from 检验报告记录 a, 检验申请组合 b, 检验组合项目 c, 诊疗项目目录 d
where a.id = b.标本id
and b.紧急 = /*B2*/'0'/*E2*/
and b.申请时间 between /*B0*/TO_DATE('2024-04-10 00:00:00','YYYY-MM-DD HH24:MI:SS')/*E0*/
and /*B1*/TO_DATE('2024-04-10 23:59:59','YYYY-MM-DD HH24:MI:SS')/*E1*/
and b.组合id = c.id
and c.诊疗编码 = d.编码
and d.id in(1085,1075,6024,1092,8018,1058,1077,8914,4822,8015,1166,1081,32188,32003,17498,17499)
and b.病人来源=1
and a.采样时间 is not null
and a.审核时间 is not null
group by d.名称
)) A,( select row_number() over(partition by 名称 order by 中位数时间差 ) 序号,中位数时间差,名称 from (
select
-- round(TO_NUMBER((a.采样时间-b.申请时间) * 24 * 60), 1) 中位数时间差,
trunc(((a.审核时间-a.采样时间) * 24 * 60)) 中位数时间差,
d.名称
from 检验报告记录 a, 检验申请组合 b, 检验组合项目 c, 诊疗项目目录 d
where a.id = b.标本id
and b.紧急 = /*B2*/'0'/*E2*/
and b.申请时间 between /*B0*/TO_DATE('2024-04-10 00:00:00','YYYY-MM-DD HH24:MI:SS')/*E0*/
and /*B1*/TO_DATE('2024-04-10 23:59:59','YYYY-MM-DD HH24:MI:SS')/*E1*/
and b.组合id = c.id
and c.诊疗编码 = d.编码
and d.id in(1085,1075,6024,1092,8018,1058,1077,8914,4822,8015,1166,1081,32188,32003,17498,17499)
and b.病人来源=1
and a.采样时间 is not null
and a.审核时间 is not null
order by 中位数时间差 desc ) ) b where a.中位数=b.序号 and a.项目=b.名称
)
group by 项目 ,中位数
) group by 项目
union all
select 项目,null 中位数时间差, sum(百分之九十时间差)/2 as 百分之九十时间差,标本数 from (
select 项目, null 中位数,null 中位数时间差, 百分之九十时间差,标本数 from
(
select case mod(标本数*0.9,1) when 0 then (标本数*0.9) else (trunc(标本数*0.9)+1) end 百分之九十,标本数,项目 from (
select count(a.id) as 标本数,d.名称 as 项目
from 检验报告记录 a, 检验申请组合 b, 检验组合项目 c, 诊疗项目目录 d
where a.id = b.标本id
and b.紧急 = /*B2*/'0'/*E2*/
and b.申请时间 between /*B0*/TO_DATE('2024-04-10 00:00:00','YYYY-MM-DD HH24:MI:SS')/*E0*/
and /*B1*/TO_DATE('2024-04-10 23:59:59','YYYY-MM-DD HH24:MI:SS')/*E1*/
and b.组合id = c.id
and c.诊疗编码 = d.编码
and d.id in(1085,1075,6024,1092,8018,1058,1077,8914,4822,8015,1166,1081,32188,32003,17498,17499)
and b.病人来源=1
and a.采样时间 is not null
and a.审核时间 is not null
group by d.名称
) ) C ,
(select row_number() over(partition by 名称 order by 百分之九十时间差 ) 序号,百分之九十时间差,名称
from(
select
--round(TO_NUMBER((a.采样时间-b.申请时间) * 24 * 60), 1) 时间差,
trunc(((a.审核时间-a.采样时间) * 24 * 60)) 百分之九十时间差,
d.名称
from 检验报告记录 a, 检验申请组合 b, 检验组合项目 c, 诊疗项目目录 d
where a.id = b.标本id
and b.紧急 = /*B2*/'0'/*E2*/
and b.申请时间 between /*B0*/TO_DATE('2024-04-10 00:00:00','YYYY-MM-DD HH24:MI:SS')/*E0*/
and /*B1*/TO_DATE('2024-04-10 23:59:59','YYYY-MM-DD HH24:MI:SS')/*E1*/
and b.组合id = c.id
and c.诊疗编码 = d.编码
and d.id in(1085,1075,6024,1092,8018,1058,1077,8914,4822,8015,1166,1081,32188,32003,17498,17499)
and b.病人来源=1
and a.采样时间 is not null
and a.审核时间 is not null
order by 百分之九十时间差) ) D where C.百分之九十=D.序号 and c.项目=d.名称
union all
select 项目, null 中位数,null 中位数时间差, 百分之九十时间差,标本数 from
(
select case mod(标本数*0.9,1) when 0 then ((标本数*0.9)+1) else (trunc(标本数*0.9)+1) end 百分之九十,标本数,项目 from (
select count(a.id) as 标本数,d.名称 as 项目
from 检验报告记录 a, 检验申请组合 b, 检验组合项目 c, 诊疗项目目录 d
where a.id = b.标本id
and b.紧急 = /*B2*/'0'/*E2*/
and b.申请时间 between /*B0*/TO_DATE('2024-04-10 00:00:00','YYYY-MM-DD HH24:MI:SS')/*E0*/
and /*B1*/TO_DATE('2024-04-10 23:59:59','YYYY-MM-DD HH24:MI:SS')/*E1*/
and b.组合id = c.id
and c.诊疗编码 = d.编码
and d.id in(1085,1075,6024,1092,8018,1058,1077,8914,4822,8015,1166,1081,32188,32003,17498,17499)
and b.病人来源=1
and a.采样时间 is not null
and a.审核时间 is not null
group by d.名称
) ) C ,
(select row_number() over(partition by 名称 order by 百分之九十时间差 ) 序号,百分之九十时间差,名称
from(
select
--round(TO_NUMBER((a.采样时间-b.申请时间) * 24 * 60), 1) 时间差,
trunc(((a.审核时间-a.采样时间) * 24 * 60)) 百分之九十时间差,
d.名称
from 检验报告记录 a, 检验申请组合 b, 检验组合项目 c, 诊疗项目目录 d
where a.id = b.标本id
and b.紧急 = /*B2*/'0'/*E2*/
and b.申请时间 between /*B0*/TO_DATE('2024-04-10 00:00:00','YYYY-MM-DD HH24:MI:SS')/*E0*/
and /*B1*/TO_DATE('2024-04-10 23:59:59','YYYY-MM-DD HH24:MI:SS')/*E1*/
and b.组合id = c.id
and c.诊疗编码 = d.编码
and d.id in(1085,1075,6024,1092,8018,1058,1077,8914,4822,8015,1166,1081,32188,32003,17498,17499)
and b.病人来源=1
and a.采样时间 is not null
and a.审核时间 is not null
order by 百分之九十时间差) ) D where C.百分之九十=D.序号 and c.项目=d.名称
) group by 项目,标本数
)
group by 项目