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 |
|
deco10
Starting Member
28 Posts |
Posted - 2010-04-23 : 14:47:38
|
| My tables look like this:Order:OrderId*customerdatetimeOrderRows:OrderId*RowIditemcostHow do I get the value of the average order with sql? (I'm using MySQL but I can figure it out if I have the basic syntax).Thanks :) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-23 : 14:50:09
|
Seems likeSELECT SUM(COst)*1.0/COUNT(DISTINCT OrderId) FROM OrderRows ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
ms65g
Constraint Violating Yak Guru
497 Posts |
Posted - 2010-04-23 : 14:54:21
|
| If you mean average per each orderidSELECT (SUM(COST)+0.0)/COUNT(*) AS AVGFROM OrderRowsGROUP BY OrderId |
 |
|
|
deco10
Starting Member
28 Posts |
Posted - 2010-04-23 : 15:21:14
|
| Sorry, I left out an important detail of my tables* = PKOrder:Customer*OrderId*customerdatetimeOrderRows:Customer*OrderId*RowId*itemcost |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-23 : 15:23:36
|
| you need to tell on what basis you want averagejust average order value or average value per order oraverage order value per customer------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
deco10
Starting Member
28 Posts |
Posted - 2010-04-23 : 15:33:39
|
| Wow all of those would be good now that you mention it.But for now just the average value of each order. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-23 : 15:37:02
|
| then second suggestion will be enough------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|