Emir Cabukoglu Emir Cabukoglu - 1 year ago 90
SQL Question

SQL database averaging a value for distinct people

enter image description here

I would like to average the weights which can be seen in the picture.
That means the calculation I want to make is : (50+65+70+68+70)/5
Do you know how to do that? (to specifically select the weights ones for every person using the household number and person number)

Answer Source

Seem you want to average the distinct weights per household:

SELECT AVG(Weight)
FROM
 (
   SELECT DISTINCT HouseHoldNumber, Weight -- maybe need to add TravelNumber or PersonNumber
   FROM tab
 ) AS dt