Results are multiplied when using SUM() and GROUP BY
Posted on 2008-10-24
I'm attempting to run the following query on a table:
select distinct(batch_number),sum(amount),count(*) from tablename where
time > '2008-10-22' and time < '2008-10-23'
group by batch_number
It appears the results are multiplied greatly. The maximum count(*) I should get is 280, but I'm getting 1120, 560, etc. If I remove the distinct(batch_number) and group by batch_number, I get the correct totals. The problem is, I need that batch_number to know which batch has which amounts. This is for Microsoft SQL Server.