Ticket #732 (closed defect: fixed)
using multiple aggregates in HAVING
| Reported by: | pookey | Owned by: | zYne |
|---|---|---|---|
| Priority: | minor | Milestone: | 2.0.0 (OLD) |
| Component: | Query/Hydration | Version: | |
| Severity: | Keywords: | ||
| Cc: | Has Test: | ||
| Status: | Has Patch: |
Description
Using multiple aggregates in HAVING causes a problem.. have a look here how the second SUM fails to be turned into the correct table alias in SQL.
$q = Doctrine_Query::create()
->from('BalancedTransfer bt')
->where('bt.id IN (SELECT bt1.id FROM BalancedTransfer bt1
INNER JOIN bt1.Transfers t
INNER JOIN t.TransactionIn ti
INNER JOIN t.TransactionOut to
GROUP BY bt1.id, bt1.amount
HAVING (SUM(ti.amount) != SUM(to.amount)))')
results in
SELECT b.id AS b__id, b.amount AS b__amount, b.created_at AS b__created_at, b.player_id AS b__player_id FROM balanced_transfer b WHERE b.id IN (SELECT b2.id AS b2__id FROM balanced_transfer b2 INNER JOIN balanced_transfer_component b3 ON b2.id = b3.balanced_transfer_id INNER JOIN player_transfer p ON p.id = b3.player_transfer_id INNER JOIN player_transaction p2 ON p.transaction_in = p2.id INNER JOIN player_transaction p3 ON p.transaction_out = p3.id GROUP BY b2.id, b2.amount HAVING SUM(p2.amount) != SUM(to.amount))
Change History
Note: See
TracTickets for help on using
tickets.