I assume this was asked already once but I didn't find the right answer unfortunately.
I have multiple tables around customer data and all have the foreign key company_id. My goal is to have a list in which the first column gives me the company_id and the other columns aggregated values (e.g. COUNT) from other table. All grouped by the company_id
For example:
company_id | COUNT(products) | COUNT(purchases)
My approach was something like this but it didn't work out and I can't make up my mind of it (apart from using vlookups in excel)
SELECT pro.company_id, COUNT(*)
(SELECT pu.company_id, COUNT(*) FROM purchases pu GROUP BY pu.company_id) as 'COUNT(Purchases)'
FROM products pro
GROUP BY pro.company_id