📣 黑五价提前开抢|VIP一年通行证5折,蓝莓、Offer多多同步特惠
12
返回列表 发新帖
楼主: lexiewen
跳转到指定楼层
上一主题 下一主题
收起左侧

Wish Risk Analyst SQL OA

🔗
rongy2018 2019-4-2 00:45:10 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
回复

使用道具 举报

🔗
SOLONG09 2019-4-8 02:34:17 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
回复

使用道具 举报

🔗
rongy2018 2019-4-13 04:41:48 | 只看该作者
全局:
我的疑问是,如果A表中国家和月份的组合在B表里没有的话,则会Join之后被删除
比如,A 表有这么一条记录:2019-03 US 1 1000 然而B 表中没有2019-03月的记录,right join 之后 A 表里的这条记录将被从结果里删除
回复

使用道具 举报

🔗
非同凡想 2019-7-10 20:24:30 | 只看该作者
全局:
本帖最后由 非同凡想 于 2019-7-10 20:26 编辑 . ----
. .и
觉得需要full outer join.
因为月份的设置 这两个表都可能有空值。. From 1point 3acres bbs


  1. select COALESCE(s.transation_month,m.chargeback_date) as transaction_month
  2. , COALESCE(s.country, m.country) as country
  3. COALESCE(s.approve_count,0)AS approved_count
    ..
  4. COALESCE(s.approve_amount,0)AS approved_amount
  5. COALESCE(c.chargeback_count,0) AS chargeback_count
  6. COALESCE(c.chargeback_amount,0)AS chargeback_amount

  7. from
  8. (select to_chart(c.transcation_date, 'YYYY-MM') as transation_month,.
  9. t.country,.
  10. COALESCE(count(case when t.state= 'approved' then 1 else 0 end),0) as approve_count,
  11. COALESCE(sum(case when t.state= 'approved' then 1 else 0 end),0) as approve_amount,

  12. from transcation t. 1point 3 acres

  13. group by to_chart(t.transcation_date, 'YYYY-MM'), t.country) s
  14. .1point3acres
  15. full outer join

  16. (select to_chart(c.chargeback_date, 'YYYY-MM') as transation_month,
  17. t.country,
  18. count(count(case when t.state= 'approved' then 1 else 0 end),0) as chargeback_count,.
  19. sum(t.amount) as chargeback_amount

  20. from transcation t
  21. join chargebacks c on t.transcation_id = c.transcation_id

  22. group by to_chart(c.chargeback_date, 'YYYY-MM'),t.country) m
  23. . 1point 3 acres
  24. on s.transation_month= m.chargeback_date and s.country = m.country. check 1point3acres for more.
复制代码



补充内容 (2019-7-11 09:33):. .и
这个有bug忽略吧
回复

使用道具 举报

🔗
非同凡想 2019-7-10 20:28:06 | 只看该作者
全局:
SOLONG09 发表于 2019-3-24 09:02. Χ
第二题:. From 1point 3acres bbs
SELECT
B.month AS transaction_month
.1point3acres
觉得需要full outer join 啊 虽然可能能过test case 但是觉得 full outer join 才能包括所有的情况
回复

使用道具 举报

🔗
非同凡想 2019-7-11 09:32:48 | 只看该作者
全局:
非同凡想 发表于 2019-7-10 20:24
觉得需要full outer join.
因为月份的设置 这两个表都可能有空值。

之前的有bug这个通过测试了


  1. .google  и
  2. select COALESCE(s.transation_month,m.transation_month) as transaction_month
  3. , COALESCE(s.country, m.country) as country,
  4. COALESCE(s.approve_count,0)AS approved_count,
  5. COALESCE(s.approve_amount,0)AS approved_amount,
  6. COALESCE(m.chargeback_count,0) AS chargeback_count,.--
  7. COALESCE(m.chargeback_amount,0)AS chargeback_amount

  8. from. 1point3acres.com
  9. (select DATE_FORMAT(t.transaction_date, '%Y-%m') as transation_month,
  10. t.country,
  11. COALESCE(sum(case when t.state= 'approved' then 1 else 0 end),0) as approve_count,
  12. COALESCE(sum(case when t.state= 'approved' then t.amount else 0 end),0) as approve_amount

  13. from Transactions t.google  и

  14. group by DATE_FORMAT(t.transaction_date, '%Y-%m'), t.country) s

  15. left  join

  16. (select DATE_FORMAT(c.chargeback_date, '%Y-%m') as transation_month,
  17. t.country,
  18. COALESCE(sum(case when t.state= 'approved' then 1 else 0 end),0) as chargeback_count,
  19. COALESCE(sum(t.amount),0) as chargeback_amount

  20. from Transactions t
  21. join Chargebacks c on t.transaction_id = c.transaction_id
    -baidu 1point3acres
  22. group by DATE_FORMAT(c.chargeback_date,'%Y-%m'),t.country) m

  23. on s.transation_month= m.transation_month and s.country = m.country

  24. union
  25. select COALESCE(s.transation_month,m.transation_month) as transaction_month.1point3acres
  26. , COALESCE(s.country, m.country) as country,
  27. COALESCE(s.approve_count,0)AS approved_count,
  28. COALESCE(s.approve_amount,0)AS approved_amount,
  29. COALESCE(m.chargeback_count,0) AS chargeback_count,
  30. COALESCE(m.chargeback_amount,0)AS chargeback_amount

  31. from. 1point 3acres
  32. (select DATE_FORMAT(t.transaction_date, '%Y-%m') as transation_month,
  33. t.country,
  34. COALESCE(sum(case when t.state= 'approved' then 1 else 0 end),0) as approve_count,
  35. COALESCE(sum(case when t.state= 'approved' then t.amount else 0 end),0) as approve_amount. ----

  36. from Transactions t. 1point3acres.com

  37. group by DATE_FORMAT(t.transaction_date, '%Y-%m'), t.country) s
  38. . .и
  39. right  join

  40. (select DATE_FORMAT(c.chargeback_date, '%Y-%m') as transation_month,
  41. t.country,
  42. COALESCE(sum(case when t.state= 'approved' then 1 else 0 end),0) as chargeback_count,
  43. COALESCE(sum(t.amount),0) as chargeback_amount.--
  44. . Waral dи,
  45. from Transactions t
  46. join Chargebacks c on t.transaction_id = c.transaction_id
  47. group by DATE_FORMAT(c.chargeback_date,'%Y-%m'),t.country) m

  48. on s.transation_month= m.transation_month and s.country = m.country
复制代码
回复

使用道具 举报

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

本版积分规则

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