I am looking for an effective way to assign a Z-Score (also known as a standard score) for each row in a MySQL table.

Z = Z-Score X = Actual value μ = Mean value σ = Standard Deviation
I tried:
SELECT pTime,(M1-AVG(M1))/STD(M1), (M2-AVG(M2))/STD(M2), (M3-AVG(M3))/STD(M3), (M4-AVG(M4))/STD(M4) FROM mergebuys;
but in the end there was only 1 row.
It seems really inefficient to use a subquery when it only needs to be calculated.
source share