STEVESKI07
Member
- Joined
- Sep 12, 2007
- Messages
- 17
- Programming Experience
- 1-3
Hey everyone, I'm having a hard time nesting my Select statements. A simplified version of what I'm trying to do is find the average cost a person spends at a store. A person can make one or multiple purchases, so first I'm getting the total amount they spend and grouping that by the person's name. After that I want to take the average of those numbers, but SQL isn't liking it. This is what I have:
I know usually when you nest Select statements you do it in the WHERE or IN clause, but is it possible to do it in the FROM clause? I know I could always create a temp table and Select from there, but it seems like that is the long way of doing it.
Thanks in advance!
VB.NET:
Select AVG(TotalPerCustomer) FROM
(Select Name, SUM(TotalCost) as TotalPerCustomer
From CustomerOrders
Group By Name)
I know usually when you nest Select statements you do it in the WHERE or IN clause, but is it possible to do it in the FROM clause? I know I could always create a temp table and Select from there, but it seems like that is the long way of doing it.
Thanks in advance!