zoukankan      html  css  js  c++  java
  • SQL 常用操作

    1、单表多条插入

      insert into ApplyLoan(表名)(ApplyCode,DataType,OrderType,)select ApplyCode,3,400,ApplyUser from ZXApplyLoan where ApplyCode not in ('ZX201605040001','ZX201605040002') (字段对应)

    2、rank() over()聚集查询排序

      select isdelete, *  from  (select ID,applycode ,isdelete ,datatype,rank() over (partition by applycode,datatype order by ID ) as IDNum from ApplyUserInfo where  datatype=3  ) a  where IDNum>1 

    3、with 多表关联查询

      ;with cte as

    (select usermail,max(AddTime) as AddTime ,COUNT(0) as Num from ESFUserLoginLog with(nolock) where addtime>'2015-06-01' and addtime<'2015-06-23' group by usermail,CONVERT(VARCHAR(10),AddTime,120)

    ),cte2 as

    (select case Finance_UserManager.NickNameFrom when '0' then '二手房金融' when '1' then '二手房集团' when '2' then '新房金融' else '新房集团' end as '集团' ,Finance_UserManager.juesename, Finance_UserManager.NickName,cte.AddTime,cte.Num from cte,Finance_UserManager where cte.usermail=Finance_UserManager.Email)select * from cte2

    4、分页查询

     pageIndex  当前页第一条数据的num - 1 
                pageSize  每页几条数据
                select * from (select *,row_number() over(order by pid desc) as num from photos) as t where num > @startIndex and num<= @startIndex +@pageSize  order by pid desc

  • 相关阅读:
    Git一些其它的功能
    怎么利用GitHub
    Git 操作标签的一些命令
    Git标签管理
    Git 多人协作开发
    Git 开发新的功能分支
    Git的Bug分支----临时保存现场git stash
    Git分支管理策略
    2017ICPC南宁 M题 The Maximum Unreachable Node Set【二分图】
    偏序集的最大反链【二分图】
  • 原文地址:https://www.cnblogs.com/eric-gms/p/5594024.html
Copyright © 2011-2022 走看看