我想结合三份报告。我想计算每个表(smr_trn_tsalesenquiry,smr_trn_treceivequotation,smr_trn_tsalesorder),三个表的总计数,并使用hrm_mst_temployee中的where条件employee_gid,按上述三个表中的所有主键分组。
select count(*),
(
select count(x.enquiry_gid)
from smr_trn_tsalesenquiry x
where x.created_by=a.employee_gid
) as enquiry_count,
(
select count(y.quotation_gid)
from smr_trn_treceivequotation y
where y.created_by=a.employee_gid
) as quotation_count,
(
select count(z.salesorder_gid)
from smr_trn_tsalesorder z
where z.created_by=a.employee_gid and z.salesorder_status not in('SO Amended','Cancelled','Rejected')
) as sales_count
from hrm_mst_temployee a
group by a.employee_gid;