select *
    from  表 t,
         (select id from 表 where begin = '$') t1,
         (select id from 表 where id 
                       not in (select id from 表 where begin = '$')) t2
   where (t.id = t1.id and t.begin = '$') or t.id = t2.id