【问题标题】:How many customers view the blog after their purchase?有多少客户在购买后查看博客?
【发布时间】:2020-07-17 05:10:23
【问题描述】:

购买后需要在博客上获得 # 次客户浏览(评论了一些行以显示我的想法),不确定它是否正确的方法(找到 # 次客户和浏览)对任何反馈开放,提前致谢!

期望的结果:客户数量,客户在博客上的浏览量

表格:

购买

Traffic_events_atl

有多少客户在购买后查看博客?

SELECT
  COUNT(DISTINCT p.customer_id) as num_cust, -- number of customers
  COUNT(t.visit_id) as page_views -- views made by customers
FROM
  traffic_events_atl t
JOIN
  purchases p
ON
  t.visitor_id = p.visitor_id
WHERE t.property ilike '%blog%'; -- blog specific websites;

包括输出:

【问题讨论】:

  • 那么您没有从查询中得到什么?
  • 编辑了我的帖子以显示输出,不确定它是否是获取客户和视图的正确方法。想仔细检查
  • 您不认为您应该使用 COUNT(DISTINCT p.customer_id) 来计算客户数量吗?您可以从两个表中添加一些示例数据以及您的预期输出。

标签: sql postgresql count


【解决方案1】:

嗯。 . .你似乎想要和附加条件准时:

SELECT COUNT(DISTINCT p.customer_id) as num_cust, -- number of customers
       COUNT(t.visit_id) as page_views -- views made by customers
FROM traffic_events_atl t JOIN
     purchases p
     ON t.visitor_id = p.visitor_id AND
        t.timestamp > p.timestamp
WHERE t.property ilike '%blog%'; 

注意:您可能需要考虑一个客户的多次购买。如果是这样,请提出一个新问题并提供适当的样本数据和所需的结果。

【讨论】:

    猜你喜欢
    • 2013-10-12
    • 1970-01-01
    • 1970-01-01
    • 2022-10-12
    • 1970-01-01
    • 2020-07-30
    • 2013-09-05
    • 1970-01-01
    • 2021-07-18
    相关资源
    最近更新 更多