Ste*_*ers 2 mysql sql join sql-update
我有以下查询:
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);
Run Code Online (Sandbox Code Playgroud)
查找特定城市中状态为5且年龄超过6个月(日期存储在洛杉矶)的记录.这将返回大约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);
Run Code Online (Sandbox Code Playgroud)
但它会停止并锁定数据库.我怀疑有一个问题,因为没有加入,但我尝试类似的东西:
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);
Run Code Online (Sandbox Code Playgroud)
它显然不起作用,因为更新中没有'from'.
编辑>我正在使用MySQL
update L
set L.status = 1
where L.status = 5
and L.city = "cityname"
and EXISTS (
select * from LA
where Date(LA.SomeDatetime) < Date_Sub(Now(), INTERVAL 6 MONTH)
and LA.leadid = L.ID
)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3916 次 |
最近记录: |