我在A表中有2个字段,注册时间(t1)、在此注册时间(t2),现在想统计每天注册的人数,
如果表中的某条数据,t1有值、t2没值======就按t1统计,
如果表中的某条数据,t1有值、t2有值======此时就把这条数据对应的t2值替换成t1来统计,但并没有更新到数据库中去,请问怎么解决呢,谢了
如果表中的某条数据,t1有值、t2没值======就按t1统计,
如果表中的某条数据,t1有值、t2有值======此时就把这条数据对应的t2值替换成t1来统计,但并没有更新到数据库中去,请问怎么解决呢,谢了
from tb
group by (case when t2 is null then convert(varchar(10),t1,120) else convert(varchar(10),t2,120) end)
--try
select convert(varchar(10),case when t2 is null then t1 else t2 end,120),count(*)
from tb
group by convert(varchar(10),case when t2 is null then t1 else t2 end,120)
我想在问下,对这种t1为var字段的,怎么让它从小到大排列,而 不是什么按降序(desc)排序的时候,2012-3-9比较2012-3-19大,我分析,可能是因为var型的就按一个位置一个位置比,因为9大于1,所以它就默认2012-3-9大于2012-3-19,这个怎么解决呢?谢谢了
order by cast(t1 as datetime)
select (case when t2 is null then convert(varchar(10),cast(t1 as datetime),120) else convert(varchar(10),cast(t2 as datetime),120) end) [day] , count(1) [cnt]
from tb
group by (case when t2 is null then convert(varchar(10),cast(t1 as datetime),120) else convert(varchar(10),cast(t2 as datetime),120) end)
from tb
group by (case when Convert(VARCHAR(10),t2,23) is null then Convert(VARCHAR(10),t1,23) else Convert(VARCHAR(10),t2,23) end)
from tb
group by Convert(VARCHAR(10),t1,23)