• 时间天数相差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 行受影响)
    */

  • 相关阅读:
    poj 2000
    poj1316
    poj1922
    poj2017
    poj1833 排列
    poj1338
    poj2136
    poj2242
    IE兼容html5标签
    绑定事件后,某些情况下需要解绑该事件
  • 原文地址:https://www.cnblogs.com/zengxiangzhan/p/1638194.html
Copyright © 2020-2023  润新知