sql >> Databasteknik >  >> RDS >> Mysql

Beräknar du Z-Score för varje rad i MySQL? (enkel)

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


  1. AES_ENCRYPT och AES_DECRYPT med java

  2. Databashörna:Nybörjarguide till Mysql-lagringsmotorer

  3. Använder funktionen OVER-fönster i SQLAlchemy

  4. Hur man hanterar skottsekunder i Oracle