This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sql problem - sum is Incorrect

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone show me the light here.

this statment produce the wrong sum (chgTotal) SUM(unit * charge)
- it duplicates the sum for some reason. why?






thanks
 
Paul Clapham
Sheriff
Pie
Posts: 20719
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then the query without the GROUP BY clause returns twice as many rows as you think it should. So you need more criteria in your WHERE clause to stop that from happening. Run the query without GROUP BY (and without SUM and MIN and MAX) and maybe you'll see why it is producing the duplicate records.
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably in your join, you have two records of one table mapping to one record of the other table. The join creates two records in the result set, even though there is only one record in the one table.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic