<p>I have two tables, Users and DoctorVisit</p>

<p>User
- UserID
- Name</p>

<p>DoctorsVisit
- UserID
- Weight
- Date </p>

<p>The doctorVisit table contains all the visits a particular user did to the doctor.
The user's weight is recorded per visit.</p>

<p>Query:  Sum up all the Users weight, using the last doctor's visit's numbers. (then divide by number of users to get the average weight)</p>

<p>Note: some users may have not visited the doctor at all, while others may have visited many times.</p>

<p>I need the average weight of all users, but using the latest weight.</p>

<p><b>Update</b></p>

<p>I want the average weight across all users.</p>

This should get you the average weight per user if they have visited:
```
```
select user.name, temp.AvgWeight
from user left outer join (select userid, avg(weight)
            from doctorsvisit
            group by userid) temp
    on user.userid = temp.userid
```
```