我有以下查询:
select count(L.ID)
from LA inner join L on (LA.leadid = L.ID)
where L.status = 5
and L.city = "cityname"
and Date(LA.Datetime) < Date_Sub(Now(), INTERVAL 6 MONTH);
它会查找特定城市中状态为 5 且超过 6 个月的记录(该日期存储在 LA)。这将返回大约 4k 个结果。我想将每条记录的状态值更新为 1,因此我的更新如下所示:
update L, LA
set L.status = 1
where L.status = 5
and L.city = "cityname"
and Date(LA.SomeDatetime) < Date_Sub(Now(), INTERVAL 6 MONTH);
但它会停止并锁定数据库。我怀疑有问题,因为没有加入,但我尝试类似:
update L, LA
from L inner join LA on (L.OID = LA.leadid)
set L.status = 1
where L.status = 5
and L.syscity = "cityname"
and Date(LA.SomeDatetime) < Date_Sub(Now(), INTERVAL 6 MONTH);
它显然不起作用,因为更新中没有“来自”。
编辑>我正在使用 MySQL