Mysql
 sql >> Base de données >  >> RDS >> Mysql

Calculer le Z-Score pour chaque ligne dans MySQL ? (Facile)

SELECT
    mergebuys.pTime,
    (mergebuys.M1 - aggregates.AVGM1) / aggregates.STDM1 AS z1,
    (mergebuys.M2 - aggregates.AVGM2) / aggregates.STDM2 AS z2,
    (mergebuys.M3 - aggregates.AVGM3) / aggregates.STDM3 AS z3,
    (mergebuys.M4 - aggregates.AVGM4) / aggregates.STDM4 AS z4
FROM
    mergebuys
    CROSS JOIN (
        SELECT
            AVG(M1) AS AVGM1,
            STD(M1) AS STDM1,
            AVG(M2) AS AVGM2,
            STD(M2) AS STDM2,
            AVG(M3) AS AVGM3,
            STD(M3) AS STDM3,
            AVG(M4) AS AVGM4,
            STD(M4) AS STDM4
        FROM
            mergebuys
    ) AS aggregates