关于网友提出的“ sql server 2000中的一个统计问题”问题疑问,本网通过在网上对“ sql server 2000中的一个统计问题”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: sql server 2000中的一个统计问题
描述: 如题,我在A表中有2个字段,注册时间(t1)、再次注册时间(t2),现在想统计每天注册的人数,<>
如果表中的某条数据,t1有值、t2没值======就按t1统计,<>
如果表中的某条数据,t1有值、t2有值======此时就把这条数据对应的t2值替换成t1来统计,但并数据库中的t1值并没有被t2更新,请问怎么解决呢,谢了
select t1 from user group by t1 .......这种的
解决方案1:
declare @t table(regTime datetime,reg2Time datetime)
insert into @t
select '2011-10-10',null
union all
select '2011-10-10','2012-3-15'
union all
select '2011-10-11',null
union all
select '2011-10-12','2012-3-16'
/>
union all
select '2011-10-12','2012-3-16'
union all
select '2011-10-13','2012-3-17'
union all
select '2011-10-13','2012-3-17'<>
union all
select '2011-10-13','2012-3-18'
select count(1) as 注册人数 from @t group by (case reg2Time when null then regTime else reg2Time end)
解决方案2: 可以直接当SQL语句使用
解决方案3:
/>
DELCARE @TMPT1 int
DELCARE @TMPT2 INT
DELCARE @sql varchar(100)
SET @TMPT1=(
SELECT COUNT(0) FROM A where t1 <>'')
SET @TMPT2 =(
SELECT COUNT(0) FROM A where t2 <>''
)
IF(@TMPT1<>'' && @TMPT2='')
set @sql=(SELECT COUNT(t1) FROM A group by t1)
IF(@TMPT1<>'' && @TMPT2<>'')
set @sql=(SELECT COUNT(t2) FROM A group by t2)
select @sql
解决方案4: select t1 from user where t2 is null group by t1
union all
select t2 from user where t1 is not null and t2 is not null group t2
以上介绍了“ sql server 2000中的一个统计问题”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/2104464.html