WITH nl_sentcount
AS(
Select nl_id, count(distinct user_id) as sent_num from sheet1$ Where event_type='nlsent' group by nl_id
)
, nl_opencount AS (
SELECT nl_id, count(distinct user_id) as open_num from Sheet1$ where event_type = 'nlpv' group by nl_id
)
select a.nl_id, sent_num, open_num
from nl_sentcount a
inner join nl_opencount b
on a.nl_id = b.nl_id
目前我有上述一段代码,然后结果是这样的
我想问一下如果我想在这个表里在加一列open rate (open_num/sent_num) ,应该怎么修改代码?
WITH nl_sentcount
AS(
Select nl_id, count(distinct user_id) as sent_num from sheet1$ Where event_type='nlsent' group by nl_id
)
, nl_opencount AS (
SELECT nl_id, count(distinct user_id) as open_num from Sheet1$ where event_type = 'nlpv' group by nl_id
)
select a.nl_id, sent_num, open_num,
open_num / sent_num as open_rate
from nl_sentcount a
inner join nl_opencount b
on a.nl_id = b.nl_id
WITH nl_sentcount AS( Select nl_id, count(distinct user_id) as sent_num from sheet1$ Where event_type='nlsent' group by nl_id ) , nl_opencount AS ( SELECT nl_id, count(distinct user_id) as open_num from Sheet1$ where event_type = 'nlpv' group by nl_id )open_num select a.nl_id, sent_num, open_num,open_num/sent_num num_Rate from nl_sentcount a inner join nl_opencount b on a.nl_id = b.nl_id
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632