对于 SQL 服务器:
with timecounts as (
select count(case when datediff(ss, start_time, comp_time) <= 10 then transactionId end) as q10s,
count(case when datediff(ss, start_time, comp_time) <= 60 then transactionId end) as q1m,
count(case when datediff(mi, start_time, comp_time) <= 15 then transactionId end) as q15m,
count(*) qTotal
from table
where start_time = trunc(sysdate)
)
select q10s,
q1m,
q15m,
case when qTotal <> 0 then cast(q10s as float) / qTotal end as q10sPerc,
case when qTotal <> 0 then cast(q1m as float) / qTotal end as q1mPerc,
case when qTotal <> 0 then cast(q15m as float) / qTotal end as q15mPerc
from TimeCounts
对于甲骨文:
with timecounts as (
select count(case when (comp_time - start_time) * 86400 <= 10 then transactionId end) as q10s,
count(case when (comp_time - start_time) * 86400 <= 60 then transactionId end) as q1m,
count(case when (comp_time - start_time) * 1440 <= 15 then transactionId end) as q15m,
count(*) qTotal
from myTable
where start_time = trunc(sysdate)
)
select q10s,
q1m,
q15m,
case when qTotal <> 0 then cast(q10s as float) / qTotal end as q10sPerc,
case when qTotal <> 0 then cast(q1m as float) / qTotal end as q1mPerc,
case when qTotal <> 0 then cast(q15m as float) / qTotal end as q15mPerc
from TimeCounts