'Symfony 5 & SubQuery
I've been trying to do a cascade query with the query builder for a while, I tried to do a simple sql but nothing.
if I try to run the same query by replacing the table names and columns in the mysql terminal, the query works perfectly.
Here is the query in full which includes the subquery.
$entityManager = $this->getEntityManager();
$query = $entityManager->createQuery(
"SELECT
COALESCE(SUM(tp.profit_loss_value),0) AS sum_tot,
COALESCE(SUM(tp.profit_loss_perc),0) AS sum_perc,
COALESCE(SUM(tp.fee_value),0) AS fee_sum_tot,
COALESCE(SUM(tp.fee_perc),0) AS fee_sum_perc,
SELECT COALESCE(SUM(tmp.d),0)/COUNT(tmp.d) AS delta
FROM
(
SELECT COALESCE
( SUM( tpp.DeltaDurationTrade ), 0 ) / COUNT( tpp.id ) AS d
FROM
App\Entity\TraderPerformanceBinance tpp
WHERE
tpp.user = :user AND
tpp.userWalletApi = :userWalletApi
GROUP BY
DAYOFMONTH( tpp.EndTradeDate )
) AS tmp
FROM App\Entity\TraderPerformanceBinance tp
WHERE
tp.user = :user AND
tp.userWalletApi = :userWalletApi AND
tp.EndTradeDate >= :from AND
tp.EndTradeDate <= :to
"
)
->setParameter('user', $user)
->setParameter('userWalletApi', $userWalletApi)
->setParameter('from', $from)
->setParameter('to', $to);
return $query->getResult();
This is the error:
[Syntax Error] line 0, col 301: Error: Expected IdentificationVariable | ScalarExpression | AggregateExpression | FunctionDeclaration | PartialObjectExpression | "(" Subselect ")" | CaseExpression, got 'SELECT'
Thanks in advance for the suggestions.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
