Re: Update existing value on column using a database MySql version 8.0.17
Thanks for reply.
I have tried this select query... the results it's correct but how to do update my table?
mysql> SELECT
r1 AS id,
DATA,
sID
FROM
( SELECT DATA, sID, ROW_NUMBER() OVER ( PARTITION BY DATA ORDER BY sID ASC ) AS r1 FROM t3 ) AS t3
WHERE
r1 = 1 UNION ALL
SELECT
r2 + 1,
DATA,
sID
FROM
( SELECT DATA, sID, ROW_NUMBER() OVER ( PARTITION BY DATA ORDER BY sID DESC ) AS r2 FROM t3 ) AS t3
WHERE
r2 = 1
ORDER BY
DATA DESC,
sID DESC;
+----+------------+-----+
| id | DATA | sID |
+----+------------+-----+
| 2 | 2019-04-30 | 22 |
| 1 | 2019-04-30 | 21 |
| 2 | 2019-04-29 | 20 |
| 1 | 2019-04-29 | 19 |
| 2 | 2019-04-28 | 18 |
| 1 | 2019-04-28 | 17 |
| 2 | 2019-04-27 | 16 |
| 1 | 2019-04-27 | 15 |
| 2 | 2019-04-26 | 14 |
| 1 | 2019-04-26 | 13 |
| 2 | 2019-04-25 | 12 |
| 1 | 2019-04-25 | 11 |
| 2 | 2019-04-24 | 10 |
| 1 | 2019-04-24 | 9 |
| 2 | 2019-04-23 | 8 |
| 1 | 2019-04-23 | 7 |
| 2 | 2019-04-22 | 6 |
| 1 | 2019-04-22 | 5 |
| 2 | 2019-04-21 | 4 |
| 1 | 2019-04-21 | 3 |
| 2 | 2019-04-20 | 2 |
| 1 | 2019-04-20 | 1 |
+----+------------+-----+
22 rows in set (0.04 sec)
Subject
Written By
Posted
Re: Update existing value on column using a database MySql version 8.0.17
April 30, 2021 02:01AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.