0

MySQL DB Table1

+----------+--------+--------+------------------+------------+------------+------------------+
| finnished| do_max | daylie | daylie_random    | daylie_min | daylie_max | daylie_lastreset
+----------+--------+--------+------------------+------------+------------+------------------+
|   551232 |   NULL |    203 |                  |      1000  |       2000 |       2021-04-20
+----------+--------+--------+------------------+------------+------------+------------------+
|    32103 |   NULL |    103 |                  |      2000  |       3000 |       2021-04-20
+----------+--------+--------+------------------+------------+------------+------------------+
|   12121  |   NULL |    53  |                  |      4000  |       5000 |       2021-04-20
+----------+--------+--------+------------------+------------+------------+------------------+
|   41222  |   NULL |    22  |                  |      5000  |       6000 |       2021-04-20
+----------+--------+--------+------------------+------------+------------+------------------+

I Used for the daylie reset:

UPDATE table1 SET daylie=0, daylie_lastreset='2021-03-20' WHERE daylie_lastreset!='2021-04-20';

I added now the daylie_random Column Heres the question:

How do I UPDATE daylie_random for each entry to a value between daylie_min and daylie_max?

I couldn't figure out how to use in this case Select FLOOR( RAND() * (max+ min) as RandomValue; within the table and get the max and min from the row itself and for each row separately

Human Khoo
  • 135
  • 3
  • 9
  • now I have to wait 90 minutes to repost my question. This does not answer and help me in all, I already figured out the random calculation, but I cant use it in my case because that does not use the ROWS daylie_min and daylie_max daylie_random is 0 because it takes any daylie_min and max but not the min and max from the row its updates UPDATE table1 SET daylie =0, daylie_random=FLOOR(daylie_min + RAND() * daylie_max), daylie_lastreset='2021-03-20' WHERE daylie_lastreset!='2021-04-20'; – Human Khoo Apr 20 '21 at 09:21
  • It does not work correctly. I thought it is getting wrong rows and mix something up. But thats not true because even using a fixed value of 100 and 200 FLOOR(100 + rand() *200); for integer values generates values like 236 So there's a error in the calculation it does not generate a value between 100 and 200 – Human Khoo Apr 20 '21 at 09:37
  • 1
    I changed the duplicate link with one that has the correct formula. – forpas Apr 20 '21 at 09:50
  • thanks! I got a headache couldn't figure it out and thought its because some mixing up, and didnt got the idea that the formula is wrong, I even used the other thread that got linked and it couldn't help me. Maybe its a idea to reopen the thread for others saving headaches using the wrong answer from other thread – Human Khoo Apr 20 '21 at 09:51
  • when searching for similar answers, you get the wrong formula thread. I didnt found this thread you linked it now. Thank you – Human Khoo Apr 20 '21 at 09:52

0 Answers0