我正在尝试查看有多少客户在购买之前直接来到了该网站(这是空白的营销媒介)。会话ID是他们进入网站且会话已开始的时间。访客ID是他们的唯一标识符。
Select
session_id,
purchase_time
FROM orders
where marketing_medium is NULL
Group by visitor_id;
答案 0 :(得分:0)
我认为这里没有理由甚至使用GROUP BY
,至少不是基于您确实告诉我们的要求。相反,也许您需要ORDER BY visitor_id
:
SELECT
visitor_id,
session_id,
purchase_time
FROM orders
WHERE
marketing_medium IS NULL
ORDER BY
visitor_id;
答案 1 :(得分:0)
如果要计算客户数量,则只需要COUNT()
而不需要GROUP BY
:
select count(visitor_id) counter
from orders
where marketing_medium is null
如果即使每位客户进行了多次购买,只要您只计算一次,请使用DISTINCT
:
select count(distinct visitor_id) counter
from orders
where marketing_medium is null