这句话我还是看不懂,select count(1) from T_Late where T_Late.Uid = T_Worker.Uid and datediff(m,latetime,Getdate()) = 1

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/07 04:12:05
这句话我还是看不懂,select count(1) from T_Late where T_Late.Uid = T_Worker.Uid and datediff(m,latetime,Getdate()) = 1

这句话我还是看不懂,select count(1) from T_Late where T_Late.Uid = T_Worker.Uid and datediff(m,latetime,Getdate()) = 1
这句话我还是看不懂,
select count(1) from T_Late where T_Late.Uid = T_Worker.Uid and datediff(m,latetime,Getdate()) = 1

这句话我还是看不懂,select count(1) from T_Late where T_Late.Uid = T_Worker.Uid and datediff(m,latetime,Getdate()) = 1
datediff是查询两个日期之间相距的函数,第一个参数为m,表示查询的是两个日期相差多少月.
算法就是第三个参数日期减去第二个参数日期.所以 datediff(m,latetime,Getdate()) = 1的意思就是字段latetime距离getdate()(当天)的有多少个月.这个就是从两个月份区分的了.比如今天是5月1日,而latetime是4月30日23点59分59秒,那么返回值也是1,即相差一个月.
前边的count(1)等同于count(*),就是查询符合条件的数据行数.
这么说能明白么?