Using aggregate SOQL, we can find the number of child records for each parent record in Salesforce.
Check the following sample SOQL. Since AccountId is grouped by, it will find the number of contact records for each Account Record.
Note:
Please add proper filters to the SOQL to make it selective.