记录一个MySQL的复杂的更新SQL

UPDATE machine m 
JOIN 
	(
	SELECT js.ID,CONCAT(jxl.JXLMC,js.SSLC,'层',js.JSMC) as JSQC FROM  gongxin_jw_jxljs as js
	JOIN  (SELECT ID,JXLMC FROM gongxin_jw_jxljs WHERE FATHER_ID = 0) as jxl on jxl.ID = js.FATHER_ID
	WHERE js.FATHER_ID <> 0
	) as js
ON m.MEMO = js.JSQC
SET m.roomid = js.ID
一个要对接的系统,本来两张表的事情,硬是塞进一张表,于是就搞出来了这么复杂的更新sql。依次留念,时时告诫自己。数据库的表也要简单话,避免一张表承担过多的责任。





你可能感兴趣的:(mysql,复杂SQL)