a
select sia_kelas.*, sia_dagur.idx, sia_dagur.nama,lk,pr
from sia_kelas
left join (select kelas,
SUM(CASE WHEN kelamin='Laki-laki' THEN 1 ELSE 0 END) as lk,
SUM(CASE WHEN kelamin='Perempuan' THEN 1 ELSE 0 END) as pr
from sia_dasis where owner='$owner->owner' and kelas!='' group by kelas) dasis
on sia_kelas.kelas=dasis.kelas
LEFT JOIN sia_dagur
ON sia_dagur.idx=sia_kelas.wali
where sia_kelas.owner='$owner->owner'
and sia_kelas.ta='$tahun'
order by nmr ASC
b