请教一个统计分析语句

Eric1006 2010-04-14 12:02:09
存在学员表
字段:
姓名 Name VARCHAR(20)
注册时间 RTime DATETIME
想计算每个月的已注册学员数量(非当月新注册学员数量),SQL语句怎么写?谢谢!
...全文
56 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
东那个升 2010-04-14
  • 打赏
  • 举报
回复
每个月的已注册学员数量(非当月新注册学员数量),包含本月的吗
东那个升 2010-04-14
  • 打赏
  • 举报
回复
select convert(char(7),RTime,114),(select count(*) from 学员表 where datediff(mm,RTime,a.RTime)>0) as num
from 学员表 a
group by convert(char(7),RTime,114)
sgtzzc 2010-04-14
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 sgtzzc 的回复:]
SQL code
select month(RTime) as m,
cnt=(select count(1) from tb where datediff(mm,t.RTime,RTime)>=0)
from tb t
group by month(RTime)
[/Quote]
嗯,加上年份比较好

select convert(varchar(7),RTime,120) as m,
cnt=(select count(1) from tb where datediff(mm,t.RTime,RTime)>=0)
from tb t
group by convert(varchar(7),RTime,120)
sgtzzc 2010-04-14
  • 打赏
  • 举报
回复
select month(RTime) as m,
cnt=(select count(1) from tb where datediff(mm,t.RTime,RTime)>=0)
from tb t
group by month(RTime)
htl258_Tony 2010-04-14
  • 打赏
  • 举报
回复
select convert(char(7),RTime,23) 月份,count(1) 学员数量
from 学员表
where datediff(mm,RTime,getdate())=0
group by convert(char(7),RTime,23)

34,594

社区成员

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

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