UPDATE tab_product_detail SET uid = (SELECT u.uid FROM tab_user u LEFT JOIN tab_namepwd p ON u.namepwd_id = p.id ) WHERE uid=0 ;
连表更新
【 表 初始化
TRUNCATE myproduct_produced_used ;
DROP TEMPORARY TABLE IF EXISTS xl_tmp_pn ;
CREATE TEMPORARY TABLE xl_tmp_pn AS SELECT COUNT(1) AS used ,uid FROM myproduct_publish GROUP BY uid ;
INSERT INTO myproduct_produced_used (total,uid,used,modify_time,create_time) SELECT v.total,v.uid,t.used,UNIX_TIMESTAMP(),UNIX_TIMESTAMP() FROM (
SELECT COUNT(1) AS total ,uid FROM myproduct WHERE status = 0 GROUP BY uid
) AS v
LEFT JOIN xl_tmp_pn t ON v.uid=t.uid
;
DROP TEMPORARY TABLE IF EXISTS xl_tmp_pn ;
】
【更新】
【
DROP TEMPORARY TABLE IF EXISTS xl_tmp_pn ;
CREATE TEMPORARY TABLE xl_tmp_pn AS SELECT COUNT(1) AS used ,uid FROM myproduct_publish GROUP BY uid ;
UPDATE myproduct_produced_used u
LEFT JOIN
(
SELECT v.total,v.uid,t.used,UNIX_TIMESTAMP()AS m FROM (
SELECT COUNT(1) AS total ,uid FROM myproduct WHERE status = 0 GROUP BY uid
) AS v
LEFT JOIN xl_tmp_pn t ON v.uid=t.uid
) AS d ON u.uid=d.uid SET u.total=d.total,u.used=d.used,u.modify_time=d.m
;
DROP TEMPORARY TABLE IF EXISTS xl_tmp_pn ;
】
JOIN 方向代表着不同的业务逻辑 : 研究对象uid增删?产品id是否增删?
测试 与生产
SELECT ori.id,ori.*,REPLACE(ori.address,"https://test.oss-cn-beijing.aliyuncs.com/","") FROM t_video ori RIGHT JOIN t_video_test t ON ori.uid=t.uid AND ori.article_id=t.article_id;
SELECT ori.id FROM t_video ori RIGHT JOIN t_video_test t ON ori.uid=t.uid AND ori.article_id=t.article_id;
UPDATE t_video_test_copy SET status=0,address=REPLACE(address,"https://test.oss-cn-beijing.aliyuncs.com/","") WHERE id IN (SELECT * FROM (
SELECT ori.id FROM t_video_test_copy ori RIGHT JOIN t_video_test t ON ori.uid=t.uid AND ori.article_id=t.article_id) AS t)
UPDATE t_video SET status=0,address=REPLACE(address,"https://test.oss-cn-beijing.aliyuncs.com/","") WHERE id IN (SELECT * FROM (
SELECT ori.id FROM t_video ori RIGHT JOIN t_video_test t ON ori.uid=t.uid AND ori.article_id=t.article_id) AS t)
update visit_copy c left join( SELECT SUM(pv) AS sumpv,uid FROM visit_middle GROUP BY uid ) d on c.uid = d.uid set c.total = d.sumpv;
update A inner join(select id,name from B) c on A.id = c.id set A.name = c.name;