I've got a handful of large tables (over 400,000 rows) that appear to be such as the following:

+---------+--------+---------------+
| ID      | M1     | M1_Percentile |
+---------+--------+---------------+
| 3684514 | 3.2997 | NULL          |
| 3684515 | 3.0476 | NULL          |
| 3684516 | 2.6499 | NULL          |
| 3684517 | 0.3585 | NULL          |
| 3684518 | 1.6919 | NULL          |
| 3684519 | 2.8515 | NULL          |
| 3684520 | 4.0728 | NULL          |
| 3684521 | 4.0224 | NULL          |
| 3684522 | 5.8207 | NULL          |
| 3684523 | 6.8291 | NULL          |
+---------+--------+---------------+...about 400,000 more

I have to assign each row within the M1_Percentile column something that signifies "the percent of rows with M1 values equal or lower to the present row's M1 value"

Quite simply, I want:

enter image description here

I implemented this sucessfully, but it's FAR Way too slow. If anybody could produce a more effective version from the following code, I'd really be thankful!

UPDATE myTable AS X JOIN (
SELECT
  s1.ID, COUNT(s2.ID)/ (SELECT COUNT(*) FROM myTable) * 100 AS percentile
FROM
  myTable s1 JOIN myTable s2 on (s2.M1 <= s1.M1)
GROUP BY s1.ID
ORDER BY s1.ID) AS Z 
ON (X.ID = Z.ID) 
SET X.M1_Percentile = Z.percentile;

This is actually the (correct but slow) derive from the above mentioned query if the amount of rows is restricted towards the ones the thing is (10 rows):

+---------+--------+---------------+
| ID      | M1     | M1_Percentile |
+---------+--------+---------------+
| 3684514 | 3.2997 |            60 |
| 3684515 | 3.0476 |            50 |
| 3684516 | 2.6499 |            30 |
| 3684517 | 0.3585 |            10 |
| 3684518 | 1.6919 |            20 |
| 3684519 | 2.8515 |            40 |
| 3684520 | 4.0728 |            80 |
| 3684521 | 4.0224 |            70 |
| 3684522 | 5.8207 |            90 |
| 3684523 | 6.8291 |           100 |
+---------+--------+---------------+

Creating exactly the same results for the whole 400,000 rows takes magnitudes longer.

I am unable to test this, but you could attempt something similar to:

update table t
set mi_percentile = (
    select count(*)
    from table t1
    where M1 < t.M1 / (
        select count(*)
        from table));

UPDATE:

update test t
set m1_pc = (
    (select count(*) from test t1 where t1.M1 < t.M1) * 100 /
    ( select count(*) from test));

This works in Oracle (the only real database I've available). I actually do remember getting that error in MySQL. It's very annoying.

Fair warning: mysql is not my native atmosphere. However, if you do research, I believe the next query ought to be workable:

UPDATE myTable AS X 
JOIN ( 
  SELECT  X.ID, (
      SELECT  COUNT(*)
      FROM    myTable X1
      WHERE   (X.M1, X.id) >= (X1.M1, X1.id) as Rank)
  FROM myTable as X
) AS RowRank
ON (X.ID = RowRank.ID)
CROSS JOIN (
  SELECT COUNT(*) as TotalCount 
  FROM myTable 
) AS TotalCount
SET X.M1_Percentile = RowRank.Rank / TotalCount.TotalCount;