anishmbait
anishmbait

Reputation: 31

SUM with left join returning incorrect result

I have 2 tables

  1. Calls
  2. Amount

I'm trying to left join both the tables to get the sum total of amount along side volume/date.

Below is the query I'm trying, however getting very huge amount as result.

SELECT
    PeriodDate, SUM(Volume), SUM(Amount)
FROM
    Calls
LEFT JOIN
    Amount ON Calls.PeriodDate = Amount.PeriodDate
GROUP BY
    PeriodDate

enter image description here

Upvotes: 0

Views: 79

Answers (1)

The Impaler
The Impaler

Reputation: 48850

You can do:

select a.*, b.amount
from (
  select perioddate, sum(volume) as volume from calls group by perioddate
) a
left join (
  select perioddate, sum(amount) as amount from amount group by perioddate
) b on b.perioddate = a.perioddate

Upvotes: 1

Related Questions