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

请教一道SQL 非常感谢大家!!

全局:

2019(4-6月) 分析|数据科学类 硕士 全职@meta - Other - 技术电面  | | Other | 在职跳槽

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
请教一道SQL, 实在不知道如何把both 0 0 显示出来,我自己的SQL答案是无法显示both 0, 0 的

Problem Statement:  Member can make purchase via either mobile  or desktop platform. Using the following data table to determine the total number of member and revenue for mobile-only, desktop_only and mobile_desktop.. check 1point3acres for more.
The input spending table is
member_id    date    channel   spend
1001    1/1/2018    mobile    100.1point3acres
1001    1/1/2018    desktop   
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
sum(spend) as total_spend, (count distinct channel) as channel_distinct
From table. 1point 3acres
Group by date, member_id) b
On a.date = b.date
And a. member_id = b.member_id.1point3acres
)
Group by date, channel
谢谢各位大佬,实在不知道如何改动能把0,0 加进去!



评分

参与人数 1大米 +20 收起 理由
匿名用户-XGGIC + 20

查看全部评分


上一篇:ehealth visualization take home
下一篇:c1莫名其妙挂经,求分析
推荐
davyzhang 2019-7-9 13:34:33 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

推荐
madeofsugar 2019-5-20 06:38:27 | 只看该作者
全局:
我是这样写的,欢迎指正。

  1. create temp table both_channel
  2. as
  3. select
  4.      date
  5.      ,'both' as channel
  6.      ,sum(tot_spend) as tot_spend
  7.      ,count(*) as tot_members
  8. from
  9. (
  10. select
  11.      member_id.--
  12.      ,date
  13.      ,count(distinct channel) as channel_cnt
  14.      ,sum(spend) as tot_spend
  15. from
  16.     table1
  17. group by
  18.       member_id
  19.       ,date
  20. having.--
  21.      count(distinct channel)=2
  22. ).--
  23. group by. check 1point3acres for more.
  24.      date;

  25. create temp table main
  26. as. check 1point3acres for more.
  27. select
  28.      date
  29.      ,channel
  30.      ,sum(spend) as tot_spend
  31.      ,count(distinct member_id) as tot_member
  32.      ,max(case when c.date is null then 1 else 0 end) as is_both_zero  --agg function is used for keeping table at date+channel granularity
  33. from
  34.     table1 as t
  35.     left join both_channel as c
    . From 1point 3acres bbs
  36.          on t.date=c.date
  37. group by
  38.       date
  39.       ,channel;. 1point 3acres
  40.        ..
  41. select * from
  42. (. From 1point 3acres bbs
  43. select
  44.      date
  45.      ,channel
  46.      ,tot_spend
  47.      ,tot_member
  48. from
  49.     main
  50. where
  51.     is_both_zero=0
  52. union all.
  53. select
  54.      date
  55.      ,channel
  56.      ,tot_spend
  57.      ,tot_member.google  и
  58. from
  59.     both_channel
  60. union all-baidu 1point3acres
  61. select
  62.      date. 1point 3 acres
  63.      ,'both' as channel
  64.      ,0 as tot_spend
  65.      ,0 as tot_member
  66. from
  67.     main-baidu 1point3acres
  68. where
  69.     is_both_zero=1  
  70. )
  71. order by. ----
  72.      date
  73.      ,channel. 1point 3acres
  74.      ,tot_spend
  75.      ,tot_member;   
  76. . 1point 3acres
复制代码

评分

参与人数 2大米 +11 收起 理由
rongy2018 + 1 给你点个赞!
匿名用户-XGGIC + 10

查看全部评分

回复

使用道具 举报

推荐
albeehere 2019-5-21 03:13:19 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies

评分

参与人数 1大米 +10 收起 理由
匿名用户-XGGIC + 10

查看全部评分

回复

使用道具 举报

全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies

评分

参与人数 1大米 +10 收起 理由
匿名用户-XGGIC + 10

查看全部评分

回复

使用道具 举报

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

评分

参与人数 1大米 +10 收起 理由
匿名用户-XGGIC + 10

查看全部评分

回复

使用道具 举报

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

评分

参与人数 1大米 +10 收起 理由
匿名用户-XGGIC + 10

查看全部评分

回复

使用道具 举报

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

评分

参与人数 1大米 +10 收起 理由
匿名用户-XGGIC + 10

查看全部评分

回复

使用道具 举报

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

评分

参与人数 1大米 +10 收起 理由
匿名用户-XGGIC + 10

查看全部评分

回复

使用道具 举报

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

评分

参与人数 1大米 +10 收起 理由
匿名用户-XGGIC + 10

查看全部评分

回复

使用道具 举报

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

本版积分规则

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