Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Norader
Starting Member
1 Post |
Posted - 2014-01-30 : 16:26:59
|
The sum in number (nnr) 1 and 2 is changing, i don't know why just in these numbers, the other numbers the sum is good. select distinct sum(mitschrifteinzel.points) as SUM, mitschrifteinzel.vernr, mitschrifteinzel.nnr,veranstaltung.verdatumfrom nennungeneinzel, veranstaltung, mitschrifteinzelwhere nennungeneinzel.vernr= veranstaltung.vernr and mitschrifteinzel.nnr=nennungeneinzel.nnr and mitschrifteinzel.vernr= veranstaltung.vernr group by mitschrifteinzel.nnr ; SUM vernr nnr 138 1 1 <------ here the SUM should be 7295 1 2 <------ here the SUM Should be 5227 1 324 1 451 1 539 1 648 1 727 1 821 1 951 1 1049 1 1166 1 1221 1 1370 1 1437 1 1566 1 1649 1 1750 1 18PLEASE HELP ME |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2014-01-30 : 16:45:41
|
Check your JOIN conditions.Also, I don't believe your query is a valid one. You are groping by nnr only, but selecting vernr as well. Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-31 : 07:33:20
|
quote: Originally posted by Norader The sum in number (nnr) 1 and 2 is changing, i don't know why just in these numbers, the other numbers the sum is good. select distinct sum(mitschrifteinzel.points) as SUM, mitschrifteinzel.vernr, mitschrifteinzel.nnr,veranstaltung.verdatumfrom nennungeneinzel, veranstaltung, mitschrifteinzelwhere nennungeneinzel.vernr= veranstaltung.vernr and mitschrifteinzel.nnr=nennungeneinzel.nnr and mitschrifteinzel.vernr= veranstaltung.vernr group by mitschrifteinzel.nnr ; SUM vernr nnr 138 1 1 <------ here the SUM should be 7295 1 2 <------ here the SUM Should be 5227 1 324 1 451 1 539 1 648 1 727 1 821 1 951 1 1049 1 1166 1 1221 1 1370 1 1437 1 1566 1 1649 1 1750 1 18PLEASE HELP ME
posted query wont even work in sql server as you're missing fields in GROUP BY. In SQL Server if you're using GROUP BY you can directly include columns in select unless they're part of GROUP BYAlso DISTINCT Is redundant here as GROUP will already make sure you get only distinct values for the involed columns------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|
|
|