2
Can anyone explain me how this mysql command will work?
SELECT @row := @row + 1 AS n_linha , m.* FROM
(SELECT b.user_id as prox_user_id, t.auctionID, t.productID, t.auc_due_price+t.auc_plus_price AS prox_valor, t.auc_due_time, b.id as id_lance, t.auc_plus_time, t.auc_plus_price
FROM bidbutler b
inner join c_cron_tempo t on b.auc_id = t.auctionID
where b.butler_status = 0 and (b.butler_bid-b.used_bids)>0
and t.auc_due_time < GREATEST(LEAST(TRUNCATE(15 * RAND(),0),15),3)
Order by b.auc_id, RAND()) m,(SELECT @row :=0) r;
Especially the RAND part, I couldn’t understand.
I know that it performs at various values of the RAND, as I could do also for it to run at a value defined by me without the RAND?
Thanks for the info. How would it be to set a random number between 1 and 5?
– Wendler
Why you have that 15 * before?
– Wendler
And zero why you’re in the middle?
– Wendler
@Wendler edited the answer to answer these questions. To change the range just change the multiplication and limits in
LEAST()andGREATEST(). The15 * RAND()is a necessary multiplication because the result ofRAND()always returns a number less than or equal to 1. Zero is the second parameter passed to theTRUNCATE(), which is the number of decimals to be maintained of the multiplication result. In the case it is no decimal box because the query wants an integer number between 3 and 15, not a fraction.– nunks