30天以内:select count(*) from TB where datediff(day,字段名,getdate()) between 0 and 30
30-60天:select count(*) from TB where datediff(day,字段名,getdate()) between 30 and 60
60-90天:select count(*) from TB where datediff(day,字段名,getdate()) between 60 and 90
90天以外:select count(*) from TB where datediff(day,字段名,getdate())>90
计算数据库中30天以内,30-60天,60-90天,90天以外的数据的个数(用sql实现)
最新推荐文章于 2025-05-07 08:30:00 发布
本文介绍了一种使用SQL按不同时间段统计记录数量的方法,通过datediff函数结合getdate()函数实现对指定日期字段进行30天内、30-60天、60-90天及90天以上的数据量统计。
&spm=1001.2101.3001.5002&articleId=5768218&d=1&t=3&u=0952af264aab4af6942b36fb7be69a8a)
454

被折叠的 条评论
为什么被折叠?



