Query does not load/very slow load

i have this query , that was build inside metabase:

SELECT STR_TO_DATE(CONCAT(DATE_FORMAT(NFeTests.dhEmi, '%Y-%m'), '-01'), '%Y-%m-%d') AS NFeTests__dhEmi, (SUM(DetNves.prodCprodVProd) + SUM(DetNves.prodCprodvFrete) + SUM(DetNves.iPIIPITribvIPI)) - SUM(DetNves.prodCprodvDesc) AS Valor_Notas
FROM Accounts
LEFT JOIN Companies AS Companies ON Accounts.id = Companies.AccountId RIGHT JOIN NFeTests AS NFeTests ON Companies.id = NFeTests.CompanyId INNER JOIN DetNves AS DetNves ON NFeTests.id = DetNves.NFeTestId LEFT JOIN Cfops AS Cfops - CfopId ON DetNves.CfopId = Cfops - CfopId.id
GROUP BY STR_TO_DATE(CONCAT(DATE_FORMAT(NFeTests.dhEmi, '%Y-%m'), '-01'), '%Y-%m-%d')
ORDER BY STR_TO_DATE(CONCAT(DATE_FORMAT(NFeTests.dhEmi, '%Y-%m'), '-01'), '%Y-%m-%d') ASC

when i remove the groupby/orderby and run it on MySQL workbench, it run normally.

what would be the best abordation to this ?

Optimize the query or scale your db vertically