Вы должны добавить правильное предложение GROUP BY (в вашем случае это должен быть category.pid)
SELECT
categories.*
, projects.pid
, projects.name
, SUM(counts.count)
, COUNT(counts.count)
, parent_category.*
, SUM(parent_category_count.count)
, COUNT(parent_category_count.count)
FROM categories
INNER JOIN projects ON projects.pid = categories.project
LEFT JOIN counts ON counts.category = categories.pid
LEFT JOIN categories AS parent_category ON parent_category.pid = categories.parent
LEFT JOIN counts AS parent_category_count ON parent_category_count.category = categories.pid
GROUP BY categories.pid
или как в вашем комментарии
SELECT
categories.*
, projects.pid
, projects.name
, SUM(counts.count)
, COUNT(counts.count)
, parent_category.*
, SUM(parent_category_count.count)
, COUNT(parent_category_count.count)
FROM categories
INNER JOIN projects ON projects.pid = categories.project
LEFT JOIN counts ON counts.category = categories.pid
LEFT JOIN categories AS parent_category ON parent_category.pid = categories.parent
LEFT JOIN counts AS parent_category_count ON parent_category_count.category = categories.pid
GROUP BY categories.pid, projects.pid, parent_category.pid