[英]mysql logic to update some records
I have a specific recordset of 48 records (1 day over 1/2 hour slots). 我有48条记录的特定记录集(1/2天时段内为1天)。
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). 我想将前24个记录中的
l
值(按l
字段DESC
排在前)减少一个已知的量,而我所拥有的就是日期和我要减少的量(一个名为$ int的php var)。
Currently, I am reducing all 48 records as such: 目前,我正在减少所有48条记录,例如:
UPDATE r SET l = l - $int WHERE thedate = '$kDate'
(updates 48 records) (更新48条记录)
How do I update the top 24? 如何更新前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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.