Update a row with position

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
vintoICT
User
Posts: 435

Update a row with position

Post by vintoICT »

i understand how to use server events or expression i ust need help with the sql .

Value | Sort
76 | 0
82 | 0
7 | 0
14 | 0

the result would be:

Value | Sort
76 | 2
82 | 1
7 | 4
14 | 3


vintoICT
User
Posts: 435

Post by vintoICT »

update table1
set sort = t.rnum
from (select table1.value, row_number() OVER (ORDER BY value desc) as rnum from table1) t;

MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'from (select table1.value, row_number() OVER (ORDER BY value desc) as rnum fr...' at line 3


vintoICT
User
Posts: 435

Post by vintoICT »

This soved the problem finaly

 update table1
set sort = (
    select count(distinct value) + 1
    from table1 w2
    
    where  w2.value > table1.value
   );

Post Reply