• 时间天数相差5天以上并且记录条数大于2的信息


    ifnotobject_id('Tempdb..#T') isnull
       
    droptable #T
    Go
    Createtable #T([ID]int,[NAME]nvarchar(1),[DTIME]Datetime)
    Insert #T
    select1,N'','2007-12-15'unionall
    select2,N'','2008-10-12'unionall
    select3,N'','2009-10-13'unionall
    select4,N'','2009-12-15'unionall
    select5,N'','2009-12-17'unionall
    select6,N'','2009-12-14'unionall
    select7,N'','2009-12-10'unionall
    select8,N'','2009-12-01'unionall
    select9,N'','2009-12-10'
    Go
    Select*from #T

    select*from[表名]wheredatediff(day,DTIme,getdate())>5and[Name]in (select[Name]from[表名]groupby[Name]havingcount([Name])>2)


    declare@iint
    select@i=count(*) from #T whereDateDiff(day,[DTIME],getdate()) >5
    if@i>2
    select*from #T whereDateDiff(day,[DTIME],getdate()) >5

    /*
    ID          NAME DTIME
    ----------- ---- -----------------------
    1           张    2007-12-15 00:00:00.000
    2           刘    2008-10-12 00:00:00.000
    3           王    2009-10-13 00:00:00.000
    7           李    2009-12-10 00:00:00.000
    8           高    2009-12-01 00:00:00.000
    9           金    2009-12-10 00:00:00.000

    (6 行受影响)
    */

  • 相关阅读:
    zbb20180930 Postman 使用方法详解
    Cookie、Session、jsp、EL、JSTL
    Http协议、Tomcat、servlet
    xml、网络编程、 反射
    JDBC、DBUtils
    Java IO流对象、多线程
    mySql
    Java基础
    VueJs
    GIT
  • 原文地址:https://www.cnblogs.com/zengxiangzhan/p/1638194.html
Copyright © 2020-2023  润新知