Simple (?) SQL Question
-
Hey guys. Got a little question I could use some help. Suppose I have a table with 2 fields : Date and Ammount. I need to write a query that displays each date and the sum of ammounts to that date. I got a bit messed up with it... Isaac
You could try joining the table onto itself
SELECT d.[Date], SUM(a.Amount)
FROM MyTable AS d
INNER JOIN MyTable AS a ON a.[Date] <= d.[Date]
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog
-
You could try joining the table onto itself
SELECT d.[Date], SUM(a.Amount)
FROM MyTable AS d
INNER JOIN MyTable AS a ON a.[Date] <= d.[Date]
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog
-
Well, I guess that happens from time to time when I type directly into Code Project rather than conduct a test first. Which is a good thing to learn: Always test code before releasing it. :-D
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog