Page 1 of 1
Update a row with position
Posted: Mon Jul 15, 2024 12:33 pm
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
Re: update a row with position
Posted: Mon Jul 15, 2024 1:16 pm
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
Re: Update a row with position
Posted: Sun Jul 21, 2024 4:34 pm
by vintoICT
This soved the problem finaly
update table1
set sort = (
select count(distinct value) + 1
from table1 w2
where w2.value > table1.value
);