left join count
| От | Greenhorn |
|---|---|
| Тема | left join count |
| Дата | |
| Msg-id | ddcb1c341002111453v1b6e75c5i6c7979e57f82d5a2@mail.gmail.com обсуждение исходный текст |
| Ответы |
Re: left join count
|
| Список | pgsql-general |
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 :)
В списке pgsql-general по дате отправления: