select recordid,count(*) from (
select a.recordid,
a.name,
a.billid,
a.baseid,
a.storename,
b.billleftnumb,
b.materielsname,
b.recordid as iid
from wzgl.view_bill a,
wzgl.view_bill_materiel_request b
where a.recordid = b.billid ) as tmp
group by recordid