반응형
누적접속자
select aa.date
,aa.server
,count(distinct accountid) --dau
,sum(count(x)) over (partition by server order by aa.date) -- 누적 접속자
from
(
select date
,server
,accountid
,row_number() over(partition by server, accountid order by date asc) as x
from workdb2.dbo.dau2 with (nolock)
where
date between '2020-07-01' and '2020-07-02'
) as aa
group by
aa.date
,aa.server
최초구매
select aaa.productname, suM(aaa.[user]) 'user'
from
(
select bb.productname, bb.server, count(distinct bb.accountid) 'user'
from
(
select server, accountid
from [example].[dbo].[all_nru]
where
cast(time as date) between '2020-01-21' and '2020-02-18' ------ 기간
group by
server, accountid
) as aa,
(
select a.server, a.accountid, b.productname, a.time, ROW_NUMBER () over (partition by a.server, a.accountid order by a.time asc) as rn
from workdb.dbo.purchase a with (nolock)
join workdb.dbo.cm_purchase b with (nolock) on a.clientproductid=b.clientproductid
and
cast(a.time as date) >=cast(b.created_Date as date) and cast(a.time as date) < cast(b.deleted_Date as date)
where
cast(a.time as date) between '2020-01-21' and '2020-02-18' ------ 기간
) as bb
where
aa.server=bb.server and aa.accountid=bb.accountid and rn= 7 ----- 최초~N번쨰 구매횟수
group by
bb.productname, bb.server
) as aaa
group by
aaa.productname
order by
2 desc
반응형
'sql' 카테고리의 다른 글
[sql] 날짜별 이동평균, 월간 누적매출, 매출 z차트 만들기 (0) | 2022.09.26 |
---|---|
[sql] 특정 문자만 추출, 월초, 월말 집계 방법, 스케쥴러 조회 (0) | 2022.09.26 |
[SQL] 잔존율 retention 집계 하기 D+7, M+1 (0) | 2022.09.26 |
[sql] DB 컬럼 정보 조회 방법, sp 내용 확인하기 (0) | 2022.09.26 |
[sql] 과금 구간별 10단위 ntile ,중앙값 구하기 (0) | 2022.09.26 |
댓글