求一个统计SQL语句

liuhui810 2009-09-03 04:32:46
比如,从8月1日到8月31日,每天注册的人数。

数据库里有regisDate项。

谢谢。
...全文
74 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
soft_wsx 2009-09-03
  • 打赏
  • 举报
回复
按日期分组!用count(1)统计记录数就可以了!
soft_wsx 2009-09-03
  • 打赏
  • 举报
回复
/*
Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86) Jul 9 2008 14:43:34 Copyright (c)
1988-2008 Microsoft Corporation Enterprise Evaluation Edition on Windows NT 5.1 <X86>
(Build 2600: Service Pack 3)
愿和大家共同进步
如有雷同、实属巧合
●●●●●2009-09-03 14:10:36.077●●●●●
 ★★★★★soft_wsx★★★★★
*/
if object_id('tb') is not null drop table tb
create table tb(rq varchar(10),name varchar(20))
go
insert tb
select
'2009-9-1', 'tom'
union all select '2009-9-1', 'jack'
union all select '2009-9-1', 'tom'
union all select '2009-9-2', 'bill'
union all select '2009-9-2', 'tim'
union all select '2009-9-3', 'john'
union all select '2009-9-4', 'tom'
union all select '2009-9-4', 'kite'
union all select '2009-9-4', 'john'
union all select '2009-9-5', 'tom'

select rq as 日期,COUNT(distinct(name)) as 登录用户数 from tb(nolock)
group by rq

/*
日期 登录用户数
2009-9-1 2
2009-9-2 2
2009-9-3 1
2009-9-4 3
2009-9-5 1
*/

select rq as 日期,COUNT(name) as 登录用户数 from tb(nolock)
group by rq
/*
日期 登录用户数
2009-9-1 3
2009-9-2 2
2009-9-3 1
2009-9-4 3
2009-9-5 1
*/
vipper23 2009-09-03
  • 打赏
  • 举报
回复
declare @i int
set @i= 20080801
create table #a (regdate int, regcount int)
while @i<20080832
begin
insert into #a select @i,count(1) from tb where regisDate=convert(varchar(10),@i)
set @i = @i+1
end
select * from #a

drop table #a

snwgija 2009-09-03
  • 打赏
  • 举报
回复
select count(1) '注册总人数' from tb
where convert(varchar(8),regisDate,120) >='2009-08-01' and convert(varchar(8),regisDate,120)<='2009-08-31'
snwgija 2009-09-03
  • 打赏
  • 举报
回复
答题基本靠猜````
htl258_Tony 2009-09-03
  • 打赏
  • 举报
回复
select convert(char(10),regisDate,23) regisDate,
count(1) cnt
from tb
where regisDate between '2009-08-01' and '2009-08-31'
group by convert(char(10),regisDate,23)
看来快不得
--小F-- 2009-09-03
  • 打赏
  • 举报
回复
select 
convert(varchar(10),regisDate,120) as regisDate,
count(1) as 人数
from
tb
where
convert(varchar(10),regisDate,120) between '2009-08-01' and '2009-08-31'
group by
convert(varchar(10),regisDate,120)
--小F-- 2009-09-03
  • 打赏
  • 举报
回复
[code=SQLselect
convert(varchar(10),regisDate,120) as regisDate,
count(1) as 人数
from
tb
where
convert(varchar(10),regisDate,120) between '2009-08-01' and '2009-08-31'
group by
convert(varchar(10),regisDate,120) ][/code]
--小F-- 2009-09-03
  • 打赏
  • 举报
回复
select
convert(varchar(10),regisDate,120) as regisDate,
count(1) as 人数
from
tb
where
convert(varchar(10),regisDate,120) between '2009-08-01' and '2009-08-31'
group by
convert(varchar(10),regisDate,120)
dawugui 2009-09-03
  • 打赏
  • 举报
回复
[Quote=引用楼主 liuhui810 的回复:]
比如,从8月1日到8月31日,每天注册的人数。

数据库里有regisDate项。

谢谢。
[/Quote]
select [day],count(1) from tb group by [day]
select convert(varchar(10),[day],120),count(1) from tb group by convert(varchar(10),[day],120)
jiangshun 2009-09-03
  • 打赏
  • 举报
回复
select 人数=count(1) from 表 where regisDate>='2009-8-1' and regisDate<='2009-8-31'
group by convert(varchar(10),regisDate,120)
--小F-- 2009-09-03
  • 打赏
  • 举报
回复
select 日期,count(1) as 数量 from tb group by 日期
htl258_Tony 2009-09-03
  • 打赏
  • 举报
回复
select regisDate,count(1) cnt from tb where regisDate between '2009-08-01' and '2009-08-31' group by regisDate
modify
百年树人 2009-09-03
  • 打赏
  • 举报
回复
select 
convert(varchar(10),regisDate,120) as regisDate,
count(distinct [user])
from
tb
where
convert(varchar(10),regisDate,120) between '2009-08-01' and '2009-08-31'
group by
convert(varchar(10),regisDate,120)
lihan6415151528 2009-09-03
  • 打赏
  • 举报
回复
SELECT COUNT(*) FROM TB
WHERE regisDate BETWEEN 2009-8-1 AND 2009-8-31
guguda2008 2009-09-03
  • 打赏
  • 举报
回复
SELECT regisDate,COUNT(1)'注册人数' FROM TB
GROUP BY regisDate
htl258_Tony 2009-09-03
  • 打赏
  • 举报
回复
select regisDate,count(1) cnt from tb group by regisDate
htl258_Tony 2009-09-03
  • 打赏
  • 举报
回复
如果当天为0也要显示吗?

34,590

社区成员

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

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