Average of multiple columns

前端 未结 5 1908
执念已碎
执念已碎 2020-12-01 14:13

I have a table called Request and the data looks like:

Req_ID    R1   R2   R3   R4   R5

R12673    2    5    3    7    10
R34721    3    5    2    1    8
R27         


        
5条回答
  •  情歌与酒
    2020-12-01 14:22

    You could simply do:

    Select Req_ID, (avg(R1)+avg(R2)+avg(R3)+avg(R4)+avg(R5))/5 as Average
    from Request
    Group by Req_ID
    

    Right?

    I'm assuming that you may have multiple rows with the same Req_ID and in these cases you want to calculate the average across all columns and rows for those rows with the same Req_ID

提交回复
热议问题