select count(*) from (select * from messageview where threadid in (select threadid from (select b.*, c.dreplycount from (select threadid, count(*) as replycount from messageview where isthread = 0 group by threadid) b, (select threadid, count(*) as dreplycount from messageview a where a.isthread = 0 and a.state = 1 group by threadid) c where b.replycount >= 10 and b.threadid = c.threadid) where dreplycount / replycount >= 0.5) and isthread = 1 and state = 0 order by creationdate desc); elapsed:3748s result: 728 分析:
select count(1) from (select mv.threadid from messageview mv, messageview mv2 where mv.isthread = 0 and (mv2.state = 0 and mv.threadid = mv2.threadid and mv2.isthread = 1) group by mv.threadid having sum(mv.state) / count(1) >= 0.5 and count(1) >= 10);