Mysql日常函数

    技术2022-05-19  18

    备注:

    其中Intolib为表的名称,inputtime为类型伟Datetime的字段

    查询当天记录:

    select * from intolib where to_days(inputtime) = to_days(now())

    查询这个星期的记录:

    select * from intolib where week(inputtime,1) = week(now(),1) and year(inputtime) = year(now())

    查询本月记录:

    select * from intolib where month(inputtime) = month(curdate()) and year(inputtime) = year(now())

    查询上月记录:

    select * from intolib where month(inputtime)=month(curdate())-1 and year(inputtime)=year(now())

    对比的MSSQL语句:

    查询当天记录(c#语句):

    string strTemp = ""; if (rbToday.Checked)      strTemp = "dd"; if (rbWeek.Checked)      strTemp = "ww"; if (rbMonth.Checked)      strTemp = "mm";

     string strSql = "select * from intolib where datediff(" + strTemp + ",inputtime,getdate())<1";

    上月记录:    strSql = "select * from intolib where datediff(mm,inputtime,getdate())<2";

     


    最新回复(0)