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

  • 相关阅读:
    java内部类与其他类变量之间的调用方式
    java线程数设置和系统cpu的关系
    IDEA设置方法自动显示参数提示
    (十)学生课程表查询
    (九)协处理器
    (八)filter的使用
    (七)多线程写入数据
    (六)mapreduce和Hbase集成
    (五)阅读推荐
    (四)region代码实现
  • 原文地址:https://www.cnblogs.com/eric-gms/p/5594024.html
Copyright © 2011-2022 走看看