sql - How to calculate the median of a row in Mysql? -




i new sql , have been struggling nan-median, example, have table 3 (million) rows, each ten numbers (or null):

row1: 1,2,3,null,4,5,6,7,8,9 ---------- row2: 2,4,null,6,8,2,1,0,9,10 ---------- row3: 1,1,1,1,null,7,2,9,9,9 ---------- 

how nan-median of each row?

according question, if have 10 columns want calculate. trick avoid null values coalesce function. use logic:

select (coalesce(col1, 0) + coalesce(col2, 0) + coalesce(col3, 0)+ coalesce(col4, 0)+coalesce(col5, 0)+coalesce(col6, 0)+coalesce(col7, 0)+coalesce(col8, 0)+coalesce(col9, 0)+.coalesce(col10, 0))/10  yourtable 




wiki

Comments

Popular posts from this blog

python - Read npy file directly from S3 StreamingBody -

python - Minimize function with Scipy minimize -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -