//select * from letters
//where id in
//( SELECT DISTINCT Parent FROM letters WHERE (Parent <> 0)
// AND (UserFrom = 'yysun' ) ) and parent=0 and Status < 2
select count(a.*) from
(select * from letters where parent=0 and status<2) as a join
(SELECT DISTINCT Parent FROM letters WHERE (Parent <> 0)
AND (UserFrom = 'yysun' )) as b
on a.id=b.parent
用in特别费时间,应该用连接语句代替子查询
或者用exists
select count(*) from letters a
where exists
( SELECT DISTINCT Parent FROM letters WHERE (Parent <> 0)
AND (UserFrom = 'yysun') and a.parent=0 and a.Status < 2
and a.id=parent)