SELECT
tenantName_tbl (c) as ten_name, c.name as c_name, COUNT (*) FROM Pub.mtcustomer AS c INNER JOIN pub.mtorder AS o ON tenantId_tbl (c) = tenantId_tbl (o) AND c.custnum = o.custnum INNER JOIN pub.mtorderline AS ol ON tenantId_tbl (o) = tenantId_tbl (ol) AND o.ordernum = ol.ordernum GROUP BY ten_name, c_name; |