set t1.Bks=
(select max(t2.EndTime) from t_diaoyonglian0703 t2
where t1.TraceID=t2.TraceID and t2.Site='bks')-
(select MIN(t2.BeginTime) from t_diaoyonglian0703 t2
where t1.TraceID=t2.TraceID and t2.Site='bks')
where t1.Date='0703'
MySQL:update B,A set B.ccc=1 where B.bbb=A.aaa
update B set ccc=1 where bbb in(select aaa from A)
这个也可以,不过效率很低的。
在update的时候不能更新select后的结果示例:
update test.table1 a
set a.name='111'
where a.id = (select max(id) from test.table1)
这个会报错,
可以通过连表解决
update test.table a
join (select max(id) as id from test.table) b
set t.name ='111'
where a.id = b.id
或
update test.table a ,(select max(id) as id from test.table) b
set a.name ='111'
where a.id = b.id
说明:
update 时,更新的表不能在set和where 中用于子查询
update 时,可以对多个表进行更新
update 后面可以做任意查询,这个作用相当于from
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)