• sqlserver:将列更新从一个表传递到另一个表 删除一个表的重复记录


    --更新数据
    1.推荐: update #t1 set #t1.c2 = #t2.c2, #t1.c3 = #t2.c3,
     #t1.c4 = #t2.c4
    from #t2
    where #t1.c1 = #t2.c1

    2.

    update  tags   set  usednumber=usednumber+(select b.usednumber
    from  tag_tousenumber b
    where tags.tagname=b.tagname and tags.channelid=b.channelid and datediff(day,b.addeddate,getdate())<1)

    会导致第一个表中有第二个表中没有的数据变成null

    3.

    update a set a.usednumber=a.usednumber+b.usednumber  from tags    a
         left join tag_tousenumber  b
         on a.tagname=b.tagname     

    同样会导致第一个表中有第二个表中没有的数据变成null

    删除一个表的重复记录

    delete bbs_sort where id in (SELECT DISTINCT a.id FROM bbs_sort AS a,bbs_sort AS b WHERE a.sign=b.sign AND a.sort_name=b.sort_name AND a.rank=b.rank AND a.id<b.id)

    字段完全重复的

    select distinct * into #Tmp from tableName
        drop table tableName
        select * into tableName from #Tmp
        drop table #Tmp

     

    获取一个表(有区县商圈)区县的列表并按照原来的排序出结果

    select MIN(id) id, district  from rent_xxx where city='北京' group by district  order by id asc

  • 相关阅读:
    桶排序
    向控件添加变量之后,类中多了什么?
    atan2&sin
    Bug(1)
    十六进制转化二进制[c]
    接口性能分析与优化
    记一次内存泄漏DUMP分析
    偏移二分查找
    iOS开发——自定义密码输入键盘
    iOS开发——手机号,密码,邮箱,身份证号,中文判断
  • 原文地址:https://www.cnblogs.com/yuanws/p/1439778.html
Copyright © 2020-2023  润新知