简体   繁体   中英

mysql logic to update some records

I have a specific recordset of 48 records (1 day over 1/2 hour slots).

I want to reduce the value of l of the top 24 records (top by l field DESC ) by a pre-known amount and all i have is the date and the amount I want to reduce by (a php var called $int).

Currently, I am reducing all 48 records as such:

UPDATE r SET l = l - $int WHERE thedate = '$kDate'

(updates 48 records)

How do I update the top 24?

Thanks in advance.

UPDATE r 
SET l = l - $int 
WHERE thedate = '$kDate'
order by l desc
limit 24
UPDATE r SET l = l - $int WHERE thedate = '$kDate'
ORDER BY l DESC
LIMIT 24
UPDATE r SET l = l - $int WHERE thedate = '$kDate' ORDER BY thedate DESC LIMIT 24

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM