zoukankan      html  css  js  c++  java
  • SQL 收集

    1.union

      CREATE TABLE dbo.#testTab 
     ( 
      Id int NOT NULL
     ) 
      insert into #testTab values(3);
     insert into #testTab values(4);
    select * from #testTab union all
      select * from #testTab 

    select * from #testTab union  
      select * from #testTab 

    select * from (select * from #testTab order by Id) as t

    select * from (select top 3 * from #testTab order by Id) as t union all
      select * from (select top 3 * from #testTab order by Id) as t

    在使用union要排序的时候必须加top

     2.date

      select dateadd(day,2,'2004-10-15')              --2004-10-17  添加天数
      select datediff(day,'2004-09-01','2004-09-18')  --17          日期间隔
      select datepart(month,'2004-10-15')             --10          获取月份
      select datename(weekday,'2004-10-15')           --Friday      获取星期几
      select convert(varchar(10),getdate(),120)       --2013-11-29  获取日期
      select convert(varchar(8),getdate(),114)        --15:39:01    获取时间
      select datename(week,'2004-10-15')              --42          获取第几周

     3.update inner join

     update a
     SET a.ProvinceId=b.ProID
     from hkb_RequirementBook a
     join sys_T_City b
     on a.CitySubstationID=b.CityID

    这个比较特殊,可以先用别名,再申明

    定义格式:

    -- 不使用别名
    UPDATE
        tb_User 
    SET 
        tb_User.pass = ''
    FROM 
        tb_User usr
    INNER JOIN 
        tb_Address addr 
    ON 
        usr.nAddressFK = addr.nAddressID
    WHERE
        usr.id=123
    
    -- 使用别名
    UPDATE 
        usr 
    SET 
        usr.pass = ''
    FROM 
        tb_User usr
    INNER JOIN 
        tb_Address addr 
    ON 
        usr.nAddressFK = addr.nAddressID
    WHERE
        usr.id=123
  • 相关阅读:
    兼容性处理
    H5 IOS 虚拟键盘不回落的问题
    git 的版本控制
    vue-devtools工具的安装
    linux下安装mysql
    Python安装pip3常见问题
    linux下安装python3
    接口_注册接口
    接口_简单get接口_第一个接口
    Python学习笔记_Redis
  • 原文地址:https://www.cnblogs.com/hongdada/p/3449675.html
Copyright © 2011-2022 走看看