php - Doctrine QueryBuilder - multiple select fields -


i have strange problem multiple select fields. query:

$query = $querybuilder             ->select(                 [                     'sum(t1.quantity) quantity_t1',                     't2.currency currency_t2',                     'sum(t1.amount - t1.promotiondiscount) amount_t1',                     'sum(round((t1.amount - t1.promotiondiscount) / ((100 + t2.tax) / 100), 2)) amount_net',                     'sum(round((t1.amount - t1.promotiondiscount) / '.exchange_rate_gbp.', 2)) amount_gbp',                     'sum(round(round((t1.amount - t1.promotiondiscount) / '.exchange_rate_gbp.', 2) / ((100 + t2.tax) / 100), 2)) amount_gbp_net'                 ]             )             ->from(sale::class, 't2')             ->join(                 salerow::class,                 't1',                 join::with,                 $querybuilder->expr()->andx(                     $querybuilder->expr()->eq('t1.saleid', 't2.id')                 )             )             ->where(                 $querybuilder->expr()->between('t2.purchasetime', ':start', ':end')             )             ->andwhere(                 $querybuilder->expr()->in('t2.orderstatus', ':status')             )             ->setparameters(                 [                     ':start' => $startdate->format('y-m-d h:i:s'),                     ':end' => $enddate->format('y-m-d h:i:s'),                     ':status' => ['pending', 'shipped']                 ]             )             ->getquery();          $results = $query->getarrayresult(); 

the query works, if change select array:

for example this:

->select(     [        't1.id',        't2.id'     ]  ) 

and strange... works:

->select(     [         'sum(t1.quantity) quantity_t1',         'sum(t1.amount - t1.promotiondiscount) amount_t1'     ] ) 

and too:

->select(     [         't2.currency currency_t2',     ] ) 

but .. not work:

->select(     [         'sum(t1.quantity) quantity_t1',         't2.currency currency_t2',     ] ) 

why?

you cannot mix aggregates non-aggregates in sql query.

because aggregate return 1 value. non-aggregate return each values.

how mix these results in response ?

other problem, use round() function in dql. function not exist, have register custom dql function.

see this question.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -