📣 独立日限时特惠: VIP通行证立减$68
楼主: stella63
跳转到指定楼层
上一主题 下一主题
收起左侧

FB onsite 关于SQL window function的使用

 
🔗
yolandance 2019-3-8 03:06:11 | 只看该作者
全局:
请问楼主 一个用户一天会有多个status吗
回复

使用道具 举报

全局:
一点思路:
回复

使用道具 举报

全局:
select Date, count(distinct t2.Account)/count(distinct t1.account)
from table t1
left join (select * from table where Status = 'Fraud') t2
on t1.account = t2.account
where t1.Spent > 0
group by Date
order by Date ASC;

select count(distinct Account) as numoffirstfraud. From 1point 3acres bbs
from table
where date = getdate()
and Status = 'Fraud'
and Account not in (
select Account
from table
where Status = 'Fraud'
and date <> dateadd(day,1,getdate())
)

补充内容 (2019-3-8 11:02):
dateadd里应该是-1,打错
回复

使用道具 举报

🔗
iriswang0501 2019-8-26 05:36:58 | 只看该作者
全局:
lydia31358 发表于 2019-2-28 10:09
我觉得row_number() over(partition by account order by date desc) as rk 这里面不应该有desc。。

+1 同意 因为加了desc是说最后一次mark成fraud是今天
回复

使用道具 举报

🔗
haohao90s 2019-8-26 05:45:17 | 只看该作者
全局:
onsite就是这道题被给了一个差评,面试官给的方法是,今天fraud account number 减去昨天 fraud account number. 别用window function, 也别今天join 昨天,后者有个edge case就是,今天open and 今天fraud的就算不到。 fb sql题有时真一言难尽
回复

使用道具 举报

🔗
吴邦毅 2019-8-26 20:47:50 | 只看该作者
全局:
Q1:
with act
as
(
select
date,
iif(spend>0, count(distinct account),0) as total_act_user
from #fb
group by
date,
spend

),fraud
as
(
select
date,-baidu 1point3acres
iif(status = 'Fraud', count(distinct account),0) as total_fraud_user
from #fb. 1point3acres.com
group by
date,
status)
. ----select
a.date,. Waral dи,
iif(a.total_act_user = 0,0, cast (cast(f.total_fraud_user as float)/a.total_act_user as float)) as Percentage
from act a .
left outer join fraud f on a.date= f.date
回复

使用道具 举报

🔗
Syndra 2019-8-27 00:56:52 | 只看该作者
全局:
料理 发表于 2019-3-4 01:39
Select date, sum(if(usertype=fraud and spend>0,1,0)) /sum(if(spend>0).1,0) as percent group by date. ...

感觉你这个有点问题的点在于如果一个user每天fraud了两次,且spend都>0,你这个就重复count了
回复

使用道具 举报

🔗
Syndra 2019-8-27 00:58:37 | 只看该作者
全局:
本帖最后由 Syndra 于 2019-8-27 01:38 编辑

Q1
Select date,
count(case when status=’Fraud’ then distinct account else NULL end) /
Count(distinct account) as percentage
From table
Where spend > 0
Group by date

Q2
Select count(distinct account)
From
(Select account, min(date) as first_fraud
From table
Where status = ‘Fraud’
Group by account)
As tmp. 1point3acres.com
Where tmp. first_fraud = getdate();
第二种方法:
Select count(distinct account). Waral dи,
From table. From 1point 3acres bbs
Where status = ‘Fraud’
And account not in (
Select account
From table
Where status = ‘Fraud’ and date < getdate();
.1point3acres
回复

使用道具 举报

🔗
maohappy2013 2019-8-27 02:16:16 | 只看该作者
全局:
第二问没有必要这么复杂
select count(*)
from (
select account,
         min(date)
from account_id. 1point3acres.com
where status = 'Fraud'
having min(date) = current()
)
回复

使用道具 举报

🔗
lzchu1992 2019-9-25 08:41:10 | 只看该作者
全局:
求问楼主概率题面的是什么呀
回复

使用道具 举报

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

本版积分规则

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