Hi All,
I'm trying to retrieve the count of notes associated for each
transactions for table energy_transactions.
But I seem to be getting (after the join) the sum of amount x count of
notes. Can someone enlighten me with this problem?
Here's the query that I am working with.
select
energy_accounts_id, count(note)
,sum(case when t.fin_year = 2010 and t.fin_quarter = 1
then t.total_amount else 0 end) as amount_current
,sum(case when t.fin_year = 2009 and t.fin_quarter = 1
then t.total_amount else 0 end) as amount_last
from energy_transactions t
left join energy_notes n on (t.id = n.energy_transactions_id)
group by energy_accounts_id, total_amount
Thanks in advance :)