22,210
社区成员
发帖
与我相关
我的任务
分享
--从最下层查起
select *,(select flm from tab where flm=t.一级目录) as 根目录 from (
select t.lm as 三级目录,t.flm as 二级目录,
(select flm from tab where flm=t.flm) as 一级目录 from tab t where lm>1001000
) t
select rq as 日期,sum(oldry) as 老用户数,sum(newry) as 新用户数 from (
select *,isnull((select top 1 1 from tab where b.yh=yh and rq<b.rq),0) as oldry,
(case when not exists (select 1 from tab where b.yh=yh and rq<b.rq) then 1 else 0 end) as newry from (
select yh,rq from (
select yh,convert(varchar(50),rq,23) as rq from tab
)a group by yh,rq
)b
)c group by rq