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

  • 相关阅读:
    kali linux命令
    kali查看beef密码
    kali的ifconfig: command not found 解决办法
    git创建分支及日常使用
    fatal: Authentication failed for 问题解决
    php开启xdebug扩展及xdebug通信原理
    yii项目开发配置
    windows上把git生成的ssh key
    yii在Windows下安装(通过composer方式)
    rar在linux下安装更新
  • 原文地址:https://www.cnblogs.com/eric-gms/p/5594024.html
Copyright © 2011-2022 走看看