我是sql的新手,我试图划分两个select语句,但没有得到正确的答案。我得到70,但答案应该是9.20% 我在这里做错了什么?
select count(clocked_in_at - starts_at)
from master_shift
where clocked_in_at is not null
and clocked_in_at <> starts_at
and date_part('minute', clocked_in_at - starts_at) > 0
/
(select count(id) from master_shift where clocked_in_at is not null)
starts_at clocked_in_at
"2015-10-15 18:00:00+00";"2015-10-15 18:15:00+00"
"2015-10-20 17:00:00+00";"2015-10-20 17:00:00+00"
"2015-10-21 20:30:00+00";"2015-10-21 20:30:00+00"
"2015-10-22 20:00:00+00";"2015-10-22 20:00:00+00"
"2015-10-23 17:00:00+00";"2015-10-23 17:00:00+00"
"2015-10-23 20:30:00+00";"2015-10-23 20:30:00+00"
"2015-10-24 18:30:00+00";"2015-10-24 18:30:00+00"
"2015-10-26 17:45:00+00";"2015-10-26 17:45:00+00"
"2015-10-26 20:30:00+00";"2015-10-26 20:30:00+00"
"2015-10-27 15:54:00+00";"2015-10-27 15:54:00+00"
答案 0 :(得分:0)
你可能想要这个:
SELECT 100 * sum(extract(second from (clocked_in_at - starts_at))) / count(id)
FROM master_shift
WHERE clocked_in_at IS NOT NULL
AND clocked_in_at <> starts_at
AND date_part('minute', clocked_in_at - starts_at) > 0;