zoukankan      html  css  js  c++  java
  • sql经典,主要是操作表与表之间的数据是否包含和表与表之间数据移动 狼

    一、今天遇到这么一个功能,要从b,c表中读取一些数据,然后插入a中,但是a中的数据不能重复

    解决方法:
    INSERT INTO a
    select * from
    (
    从b和c中读取数据
    ) as tempTable
    where tempTable.唯一标示 not in (select 唯一标示 from a )

    二、inner join 两个表,然后用得到的数据更新其中一个表

    语法:


         update tb1  
     set tb1.a = tb2.a 
     from tb1 inner join tb2  
          on tb1.id = tb2.id


    我是这样理解的,先从from后面的语句读取一个表,然后按照set语法在表中修改数据
    三、   
    多次插入同一个临时表
     第一次用  
       select into #temp from 
       --后来用  
       insert into #temp select
    四、 重A表中读取数据插入B表,在B表username会重复的情况下,保证A中的username不重复,排除重复的数据
      insert into B select * from A as a where not exists(select 1 from B where username = a.username)
    
  • 相关阅读:
    Android 手机摇一摇功能的实现
    Android 只开启一个Activity实例
    android 获取Datepicker日期
    帧动画
    进度条ProgressDialog
    AlertDialog错误
    ListView加checkBox可以实现全选等功能
    一些自己常用的工具类
    错层
    Parallax
  • 原文地址:https://www.cnblogs.com/gowhy/p/1999495.html
Copyright © 2011-2022 走看看