with duiying as(select t100.m_flg,t100.usr_id
,v_id,v_tm
from bilibili_t100 t100
left join
bilibili_t20 t20
on t100.usr_id=t20.usr_id
where date(v_tm)between '2021-02-01' and '2021-02-28'
),
ccnt as(
select
m_flg
,usr_id
,date(v_tm)
,count(v_id) as cnt from duiying
group by 1,2,3
)
select m_flg,round(avg(cnt),2)
from ccnt
group by 1
WITH UserVideoTypes AS (
SELECT
t20.usr_id,
t3.v_typ
FROM
bilibili_t20 t20
JOIN
bilibili_t3 t3 ON t20.v_id = t3.v_id
),
UserViewCategories AS (
SELECT
usr_id,
COUNT(DISTINCT v_typ) AS view_category_count
FROM
UserVideoTypes
GROUP BY
usr_id
),
FilteredUsers AS (
SELECT
usr_id
FROM
UserViewCategories
WHERE
view_category_count >= 3
),
VideoCategoryCounts AS (
SELECT
v_typ,
COUNT(DISTINCT usr_id) AS total_viewers
FROM
UserVideoTypes
GROUP BY
v_typ
),
MultiCategoryViewers AS (
SELECT
v_typ,
COUNT(DISTINCT ut.usr_id) AS multi_category_viewers
FROM
UserVideoTypes ut
JOIN
FilteredUsers fu ON ut.usr_id = fu.usr_id
GROUP BY
v_typ
),
MCVI AS (
SELECT
vc.v_typ,
mc.multi_category_viewers,
vc.total_viewers,
(mc.multi_category_viewers * 100.0 / vc.total_viewers) AS mcv_index
FROM
VideoCategoryCounts vc
LEFT JOIN
MultiCategoryViewers mc ON vc.v_typ = mc.v_typ
)
SELECT
v_typ,
multi_category_viewers,
total_viewers,
mcv_index
FROM
MCVI
ORDER BY
mcv_index DESC;
with duiying as(select t20.usr_id,t3.v_typ
from
bilibili_t20 t20
join bilibili_t3 t3
on t20.v_id=t3.v_id
group by 1,2
)
,duoge as(
select usr_id
from(
select usr_id,count(distinct v_typ) cnt
from
duiying
group by
1)a
where cnt>=3)
,duogetyp as(
select y.v_typ,count(d.usr_id) dcnt
from duiying y
join duoge d
on y.usr_id=d.usr_id
group by 1)
,aaa as
(select
v_typ,count(usr_id) as cnt
from duiying group by 1
)
selecta.v_typ,dcnt as multi_category_viewers
,cnt total_viewers
,dcnt/cnt*100 mcv_index
from duogetyp p
left joinaaa a
on a.v_typ=p.v_typ
order by mcv_index desc
with duiying as(select t20.usr_id,t3.v_typ
from
bilibili_t20 t20
join bilibili_t3 t3
on t20.v_id=t3.v_id
group by 1,2
)
,duoge as(
select usr_id
from(
select usr_id,count(distinct v_typ) cnt
from
duiying
group by
1)a
where cnt>=3)
,duogetyp as(
select y.v_typ,count(d.usr_id) dcnt
from duiying y
join duoge d
on y.usr_id=d.usr_id
group by 1)
,aaa as
(select
v_typ,count(usr_id) as cnt
from duiying group by 1
)
selecta.v_typ,dcnt as multi_category_viewers
,cnt total_viewers
,round(dcnt/cnt*100,2)mcv_index
from duogetyp p
left joinaaa a
on a.v_typ=p.v_typ
order by mcv_index desc
with duiying as(select t20.usr_id,t3.v_typ
from
bilibili_t20 t20
join bilibili_t3 t3
on t20.v_id=t3.v_id
group by 1,2
)
,duoge as(
select usr_id
from(
select usr_id,count(distinct v_typ) cnt
from
duiying
group by
1)a
where cnt>=3)
,duogetyp as(
select y.v_typ,count(d.usr_id) dcnt
from duiying y
join duoge d
on y.usr_id=d.usr_id
group by 1)
,aaa as
(select
v_typ,count(usr_id) as cnt
from duiying group by 1
)
selecta.v_typ,dcnt,cnt,round(dcnt/cnt*100,2)rate
from duogetyp p
left joinaaa a
on a.v_typ=p.v_typ
order by rate desc
with duiying as(select t20.usr_id,t3.v_typ
from
bilibili_t20 t20
join bilibili_t3 t3
on t20.v_id=t3.v_id
)
,users as(
select usr_id
from(
select
usr_id
from(
select usr_id,group_concat(distinct v_typ
order by v_typ) tag
from duiying
group by 1
)a
where tag in('汽车','IT','IT,汽车')) b
)
select
t20.usr_id,
t20.v_id,
t20.v_tm
from
bilibili_t20 t20
join users u
on u.usr_id=t20.usr_id
order by v_tm
with duiying as(select t20.usr_id,t3.v_typ
from
bilibili_t20 t20
left join bilibili_t3 t3
on t20.v_id=t3.v_id
group by 1,2
)
select
count(a.usr_id)
from(
select usr_id,count(v_typ) cnt
from duiying
group by 1
)a
left join
duiying d
on a.usr_id=d.usr_id
where cnt=1 and d.v_typ='放映厅'
with minlogin as(
select usr_id,min(v_date) mindate
from bilibili_t100
group by 1
),
newlogin as(
select mindate,count(usr_id) cnt
from minlogin
group by 1
order by 1
)
,minflg as(
select
mindate,count(t.usr_id) fcnt
from
minlogin m
left join bilibili_t100 t
onm.usr_id=t.usr_id
wherem_flg=1 andm.mindate=t.v_date
group by 1
)
select
g.mindate,g.cnt as new_users,
f.fcnt as new_members,
round(100*f.fcnt/g.cnt ,2)
from newlogin g
left join
minflg f
on g.mindate=f.mindate
order by 1
select
asminflg
,count(usr_id) cnt
from
(select usr_id,min(v_date) asminflg
from bilibili_t100
where m_flg=1
group by usr_id)a
group by asminflg
order by asminflg
with biym as
(select *,round((datediff(end_date,begin_date)+1)/30,0) as ym
,datediff(end_date,begin_date)+1 as duration
from bilibili_m1
)
,didate as(
select m_date
from bilibili_m2
where y_m between '2021-01' and '2021-12'
)
,biunion as(
select m_date
,ym
,user_id,begin_date,end_date,pay_amount/duration money
from didate d
left joinbiym m1
on d.m_date between m1.begin_date and m1.end_date
)
select
sum(case when a.ym=12 thentt end) as yearly_card
,sum(case when a.ym=6 thentt end) as half_yearly_card
,sum(case when a.ym=3 thentt end) as quarterly_card
,sum(case when a.ym=1 thentt end) as monthly_card
,round(sum(tt),2) as total_income
from(
select ym,sum(money) tt from
biunion
group by ym)a
with biym as
(select *,round((datediff(end_date,begin_date)+1)/30,0) as ym
,datediff(end_date,begin_date)+1 as duration
from bilibili_m1
)
,didate as(
select m_date
from bilibili_m2
where y_m between '2021-01' and '2021-12'
)
,biunion as(
select m_date
,ym
,user_id,begin_date,end_date,pay_amount/duration money
from didate d
left joinbiym m1
on d.m_date between m1.begin_date and m1.end_date
)
select
sum(case when a.ym=12 thentt end) as yearly_card
,sum(case when a.ym=6 thentt end) as half_yearly_card
,sum(case when a.ym=3 thentt end) as quarterly_card
,sum(case when a.ym=1 thentt end) as monthly_card
,sum(tt) as total_income
from(
select ym,sum(money) tt from
biunion
group by ym)a
with bisingle as(
select *,datediff(end_date,begin_date)+1 as diff
from bilibili_m1
)
,didate as(
select m_date,y_m
from bilibili_m2
where y_m between '2021-01' and '2021-12'
)
,biunion as(
select m_date
,y_m
,user_id,begin_date,end_date,pay_amount/diff money
from didate d
left join bisingle m1
on d.m_date between m1.begin_date and m1.end_date
)
select y_m,round(sum(money),2)
from biunion
group by 1
with bisingle as(
select *,datediff(end_date,begin_date)+1 as diff
from bilibili_m1
)
,didate as(
select m_date
from bilibili_m2
where y_m between '2021-01' and '2021-12'
)
,biunion as(
select m_date
,FLOOR((DAYOFYEAR(m_date) - 1) / 7) + 1 as nweek
,user_id,begin_date,end_date,pay_amount/diff money
from didate d
left join bisingle m1
on d.m_date between m1.begin_date and m1.end_date
)
select nweek,round(sum(money),2)
from biunion
group by 1
with bisingle as (select *
,pay_amount/(datediff(end_date,begin_date)+1) as single_amount
from bilibili_m1)
,bidate as(
select m_date
from bilibili_m2
where y_m='2021-02'
)
,hebing as(
select d.m_date,user_id,begin_date,end_date,single_amount
from bidate d
join bisingle s
on d.m_date between s.begin_date and s.end_date
)
select round(sum(single_amount),2)
from hebing
SELECT
ROUND(AVG(DATEDIFF('2021-02-13', u.bth_dt) / 365), 2) AS avg_age
FROM
tx_red_pkt_rcd r
JOIN
tx_usr_bas_info u ON r.rcv_usr_id = u.usr_id
WHERE
DATE(r.rcv_datetime) = '2021-02-13'
AND r.pkt_amt = "520.00";
SELECT
COUNT(*) AS total_sent,
SUM(CASE WHEN rcv_datetime != '1900-01-01 00:00:00' THEN 1 ELSE 0 END) AS received_count,
ROUND(SUM(CASE WHEN rcv_datetime != '1900-01-01 00:00:00' THEN 1 ELSE 0 END) / NULLIF(COUNT(*), 0) * 100, 2) AS receive_rate
FROM
tx_red_pkt_rcd
WHERE
DATE(snd_datetime) = '2021-02-13';
WITH search_click AS (
SELECT
q.usr_id,
q.key_word,
c.click_page_id,
q.search_tm,
q.session_id
FROM jx_query_rcd q
LEFT JOIN jx_click_rcd c ON q.usr_id = c.usr_id AND q.session_id = c.session_id
)
SELECT
COUNT(search_tm) AS total_searches,
COUNT(click_page_id) AS total_clicks,
ROUND((COUNT(click_page_id) / NULLIF(COUNT(search_tm), 0)) * 100, 2) AS click_rate
FROM search_click;
WITH search_click AS (
SELECT
q.usr_id,
q.key_word,
c.click_page_id,
q.search_tm,
q.session_id
FROM jx_query_rcd q
LEFT JOIN jx_click_rcd c ON q.usr_id = c.usr_id AND q.session_id = c.session_id
)
SELECT
COUNT(session_id) AS total_searches,
COUNT(click_page_id) AS total_clicks,
ROUND((COUNT(click_page_id) / NULLIF(COUNT(search_tm), 0)) * 100, 2) AS click_rate
FROM search_click;