• sqlserver学习--4(replace(),rank(),dense_rank(),update,merge)


    1.replace()函数

    UPDATE tmp_create_fminfo SET bore=REPLACE(REPLACE(bore,'',''),'','')
    --REPLACE(bore,'(',''):bore字段的左括号以空代替
    --REPLACE(REPLACE(bore,'(',''),')',''):REPLACE(bore,'(','')的右括号以空代替

    2.update语法

    单表情况:

    update tbluserinfo set usertype = '232423' from tbluserinfo where userid = '22222' and createtime > '2017-07-12'

    多表关联更新-->相当于merge语法

    update tbluserinfo set usertype = 用水类别 
    from tbluserinfo,tmp_1 where userid = 户号 and createtime > '2017-07-12'
    update tbluserinfo 
       set usertype = 用水类别,
           useraddress = isnull(地址,''),
           installdate = CONVERT(varchar(10),立户日期,121)
      from tbluserinfo,tmp_1
     where userid = 户号 and createtime > '2017-07-12'
    MERGE
    INTO tbluserinfo as info USING tmp_1 as tmp ON info.userid = tmp.户号 and info.createtime > '2017-07-12' WHEN MATCHED THEN update set   info.usertype = tmp.用水类别,   info.useraddress = tmp.地址,   info.installdate = tmp.立户日期

     rank() ,dense_rank()

    注:rank不连续,若一样,占据同一个名次,接下来的数据按照同名次总数+1的方式继续往下排。比如1,1,3,3,3,6,7

      dense_rank连续,若一样,占据同一个名次,接下来的数据按照下一名次继续往下排。比如1,1,1,2,2,3

    select top 100 PID,userid,simid,fmaddress,rank() over(order by simid desc) as rank,dense_rank() over(order by simid desc) as dense_rank
    from tblfmreadinfo



  • 相关阅读:
    html5 悬浮提示框
    ajax 接收json
    ajax 发送参数
    jquery无刷新请求ajax
    jQuery 发送 ajax json 请求
    html5 三级联动菜单
    iframe 用法
    html5 复制文字
    bootstrap表单按回车会自动刷新页面的问题
    jquery版本不兼容问题
  • 原文地址:https://www.cnblogs.com/1184212881-Ark/p/6944720.html
Copyright © 2020-2023  润新知