Search code examples
sqlms-accessms-access-2007

Sum Expression Access Query for Completed Fields


I am trying to write a code that will sum the prices of all the orders that come up when I fill out the query. For example, if I enter the ID range 1-60, I want there to be a sum column created that then sums up all the prices of ID's 1-60.

I thought it would be simple enough to just create a SUM(.....) AS Exp 1, but it tells me that there is a problem with the ID and aggregate function.

My current code looks like this:

SELECT table.ID, table.Price, SUM(table.Price) AS Exp 1 
FROM table
WHERE table.ID BETWEEN StartID AND EndID

Thank you for any help

EDIT: I should've specified this earlier, but I want to be able to see the individual prices, as well as a new column with the sum of all these prices. I plan on adding some more columns of data into the table later on.


Solution

  • If you want the sum over all the rows, then only include that in the SELECT:

    SELECT SUM(table.Price) AS Exp1 
    FROM table 
    WHERE table.ID BETWEEN StartID AND EndID