SELECT
c.id
FROM
(
SELECT
a.id,
IF( FIND_IN_SET( a.pid, @pids ) > 0,
IF( length( @pids ) - length( REPLACE ( @pids, a.pid, '' ) ) > 1,
IF( length( @pids ) - length( REPLACE ( @pids, a.id, '' ) ) > 1,
@pids, @pids := concat( @pids, ',', a.id ) ),@pids := concat( @pids, ',', a.id ) ), 0 ) AS 'plist',
IF( FIND_IN_SET( a.pid, @pids ) > 0, @pids, 0 ) AS ischild
FROM
( SELECT r.id, r.pid FROM youbang_sys_acount r ) a,
( SELECT @pids := 1 ) b
) c
WHERE
c.ischild != 0