楼主: kk12345
跳转到指定楼层
上一主题 下一主题
收起左侧

狗家 Product Analyst 电面

 
🔗
zhubq 2019-2-4 16:41:15 | 只看该作者
全局:
谢谢楼主分享!
回复

使用道具 举报

全局:
谢谢楼主分享~
回复

使用道具 举报

🔗
Coooonnie 2019-9-9 04:55:37 | 只看该作者
全局:
楼主可以试一下用running tool?
. From 1point 3acres bbs
select date, user_id
from
(
select *,. Waral dи,
sum(views) over(order by date rows between 7 preceding to current row) as cum_sum
from tbl) as t
where cum_sum >0
回复

使用道具 举报

🔗
maohappy2013 2019-9-10 04:50:10 | 只看该作者
全局:
第二个SQL不需要这么复杂。你可以create 一个 date table
with date_table as (
select distinct date. check 1point3acres for more.
from youtube_table
order by date
)
select date_table.date,
         count(distinct user_id) .1point3acres
from date_table. From 1point 3acres bbs
inner join youtube_table
on youtube_table.date BETWEEN  date_table.date AND date_table.date - '7  days' :: INTERVAL
回复

使用道具 举报

🔗
srbhmitt11 2019-11-4 01:16:55 | 只看该作者
全局:
Select a.user_id,a.date,count(distinct(b.date)) as num_days_views from table a
Left join (select * from table where view>0)b
On a.user_id=b.user_id
And b.date between a.date-8 and a.date-1
Group by 1,2
Having num_days_views=7
回复

使用道具 举报

🔗
oddguan 2019-11-6 02:41:02 | 只看该作者
全局:
想问一下楼主是先填的questionaie吗
回复

使用道具 举报

全局:
感谢楼主的分享!
回复

使用道具 举报

🔗
benrye 2019-11-15 13:06:33 | 只看该作者
全局:
maohappy2013 发表于 2019-9-10 04:50
第二个SQL不需要这么复杂。你可以create 一个 date table
with date_table as (
select distinct date

我也赞同你的做法。唯一的一点是我觉得要再加一个where限制view是大于0的

select date_table.date,
         count(distinct user_id)
from date_table
-baidu 1point3acresinner join youtube_table
on youtube_table.date BETWEEN  date_table.date AND date_table.date - '7  days' :: INTERVAL.1point3acres
where youtube_table.view > 0  -- add a where condition
group by date_table.date  -- add group by
回复

使用道具 举报

全局:
good sharing
回复

使用道具 举报

全局:

. 1point 3acres 这题在考lag window function. 面过这么多间只有看过G家考lag window function ..

create table Employee
(
date date, ..
user_id int,
view int
);
  
insert into Employee (date, user_id, view)
VALUES
('01-01-2020','1','1'),
('01-02-2020','1','0'),.1point3acres
('01-03-2020','1','0'),
('01-04-2020','1','1'),
('01-05-2020','1','1'),
('01-06-2020','1','1'),
('01-07-2020','1','1'),
('01-08-2020','1','1'),
('01-01-2020','2','0'),
('01-02-2020','2','0'),
('01-03-2020','2','0'),
('01-04-2020','2','0'),
('01-05-2020','2','0'),. 1point 3 acres
('01-06-2020','2','0'),
('01-07-2020','2','0')
;



SELECT
date,
user_id,
lag(view,7) over(partition by user_id order by date asc) as last_7_day_view.google  и
From Employee
.google  и
output:

date        user_id        last_7_day_view.
2020-01-01        1        (null)
2020-01-02        1        (null)
2020-01-03        1        (null)
2020-01-04        1        (null)
2020-01-05        1        (null)
2020-01-06        1        (null)
2020-01-07        1        (null). From 1point 3acres bbs
2020-01-08        1        1
2020-01-01        2        (null). check 1point3acres for more.
2020-01-02        2        (null)
2020-01-03        2        (null)
2020-01-04        2        (null)
2020-01-05        2        (null)
2020-01-06        2        (null)
2020-01-07        2        (null)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表