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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 calculating grand total

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-11-27 : 08:57:44
Kurt Ove writes "is it possible to calculate the grand total of a record called "price" in my database. I have approx 200 entries and all have their own price, I would like to retrive the grand total of this, and also divide it in to average monthly total"

LarsG
Constraint Violating Yak Guru

284 Posts

Posted - 2001-11-27 : 09:20:56
select sum(price) as grandTotal, avg(Price) as averagePrice
from yourTableWithPrices

Go to Top of Page

JustinBigelow
SQL Gigolo

1157 Posts

Posted - 2001-11-27 : 09:21:50
To get totals you need the sum() function. For example
select sum(unit_price) from products
for the average you need the avg() function. There are examples of using sum() and avg() together in Books On Line under the entry for the avg() function, check there for more examples.

Justin

Go to Top of Page

JustinBigelow
SQL Gigolo

1157 Posts

Posted - 2001-11-27 : 09:22:46
quote:

select sum(price) as grandTotal, avg(Price) as averagePrice
from yourTableWithPrices



Darn it, beaten to the punch. I need to watch my long winded answers.

Justin

Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2001-11-28 : 15:20:07
To get an average on a monthly basis, use the above mentioned functions in a statement with a GROUP BY on a date field. You'll probably need to use CONVERT or DATEPART to gather all dates within a month into one line.

-------------------
It's a SQL thing...
Go to Top of Page
   

- Advertisement -