zoukankan      html  css  js  c++  java
  • 连表更新

    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;

  • 相关阅读:
    python多进程(二)
    PLSQL配置
    sql语句之左连结
    点击lable标出现下拉搜索框及选择功能
    angularjs前端分页自定义指令pagination
    未经整理的工作中遇到的小问题
    晒一晒工作内容.....呵呵勿喷
    配置chrome支持本地(file协议)ajax请求
    html5+angularjs+bootstrap+springmvc+mybatis模糊查询Deme
    oracle的sql积累..&..decode函数使用
  • 原文地址:https://www.cnblogs.com/rsapaper/p/9052390.html
Copyright © 2011-2022 走看看