关于月的统计问题

lovejsp 2003-08-21 11:56:02
有一个smalldatetime的字段。
想统计每个月10到第二个月10号的记录统计。

也就是说想知道每个月10号到第二个月10号间共有多少条记录。
因为想做个月报表,但不知道语句该如何写,谢谢。
...全文
41 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
happy_0325 2003-08-21
  • 打赏
  • 举报
回复
select count(*) from table where f_date between '2003.08.10' and '2003.08.10'
lifeforu 2003-08-21
  • 打赏
  • 举报
回复
select count(1) from table where convert(varchar(10),f_date,102)>='2003.08.10'
and convert(varchar(10),f_date,102)<='2003.08.10'
pbsql 2003-08-21
  • 打赏
  • 举报
回复
假设参数为月份mm(整数,1~12),那个字段为rq,则条件为:
where (month(rq)=mm and day(rq)>=10) or (month(rq)=mm+1 and day(rq)<10) or (mm=12 and month(rq)=1 and day(rq)<10)
月光易水 2003-08-21
  • 打赏
  • 举报
回复
declare @dData datatime

select @dData = getdate() --指定日期

select count(*) from 表 where 日期字段 between @dData and DATEADD(mm, 1, @dData)


:_)
dafu71 2003-08-21
  • 打赏
  • 举报
回复
select sum(case when [date] between '2002-12-10' and '2003-1-10' then 1 else 0 end) as 'data1',sum(case when [date] between '2003-1-10' and '2003-2-10' then 1 else 0 end) as 'data2',...,sum(case when [date] between '2003-11-10' and '2003-12-10' then 1 else 0 end) as 'data12' from yourtable
lovejsp 2003-08-21
  • 打赏
  • 举报
回复
我是想做年报表啊,然后想知道每个月的数量。

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧