select p_id, count(s_id) from table where p_id = :p_id(这个就是父节点的ID) group by p_id或者查出所有父节点的:select p_id, count(s_id) from table group by p_id