日期:2014-05-18  浏览次数:20482 次

sql server 2000中的一个统计问题
如题,我在A表中有2个字段,注册时间(t1)、再次注册时间(t2),现在想统计每天注册的人数,
如果表中的某条数据,t1有值、t2没值======就按t1统计,
如果表中的某条数据,t1有值、t2有值======此时就把这条数据对应的t2值替换成t1来统计,但并数据库中的t1值并没有被t2更新,请问怎么解决呢,谢了
select t1 from user group by t1 .......这种的

------解决方案--------------------
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
------解决方案--------------------

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
------解决方案--------------------
可以直接当SQL语句使用
------解决方案--------------------
SQL code



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)