You can write a custom logic using JCR API to get the count of the component.
If you want to find the components, then get the list of component names from apps and write a search query for each of the component name. Just a simple JCR Query that would find items containing property jcr:primaryType being cq:Component within /content would work. Depending on what the content structure of your site is, the following XPath query can be used:
/jcr:root/content/mysite//*[jcr:primaryType='cq:Component']) would get you the number of all components in the mysite content tree.
Query builder or xpath or sql2 is not as flexible as RDBMS SQL . As far as i know with a single query we cannot get what your are expecting . Only way is get at the component level using a simple query-builder or sql2 query.
You can write a custom logic using JCR API to get the count of the component.
If you want to find the components, then get the list of component names from apps and write a search query for each of the component name. Just a simple JCR Query that would find items containing property jcr:primaryType being cq:Component within /content would work. Depending on what the content structure of your site is, the following XPath query can be used:
/jcr:root/content/mysite//*[jcr:primaryType='cq:Component']) would get you the number of all components in the mysite content tree.