8b9ea8ee
tangwang
feat(recommendati...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
-- 测试SQL关联 - 检查是否能获取到country_code和customer_type
-- 1. 检查最近的sensors_events有多少login_id
SELECT
COUNT(*) as total_events,
COUNT(login_id) as has_login_id,
COUNT(DISTINCT login_id) as unique_login_ids
FROM sensors_events
WHERE event IN ('click', 'purchase')
AND create_time >= DATE_SUB(NOW(), INTERVAL 7 DAY);
-- 2. 检查这些login_id在buy_account中是否存在
SELECT
COUNT(DISTINCT se.login_id) as event_login_ids,
COUNT(DISTINCT ba.id) as account_ids,
COUNT(DISTINCT ba.buyer_id) as buyer_ids
FROM sensors_events se
LEFT JOIN buy_account ba ON ba.id = se.login_id
WHERE se.event IN ('click', 'purchase')
AND se.create_time >= DATE_SUB(NOW(), INTERVAL 7 DAY);
-- 3. 检查buy_buyer_extend_option表的code字段值
SELECT
bbeo.code,
COUNT(*) as count,
pdi.name as sample_value
FROM buy_buyer_extend_option bbeo
LEFT JOIN pub_dict_item pdi ON bbeo.dict_item_id = pdi.id
GROUP BY bbeo.code
ORDER BY count DESC
LIMIT 20;
-- 4. 测试完整关联(取10条样本)
SELECT
se.anonymous_id AS user_id,
se.item_id,
se.event AS event_type,
se.login_id,
se.business_platform AS platform,
country_code_pd.name AS country_code,
customer_type_pd.name AS customer_type
FROM
sensors_events se
LEFT JOIN buy_account ba ON ba.id = se.login_id
LEFT JOIN buy_buyer bb ON bb.id = ba.buyer_id
LEFT JOIN buy_buyer_extend bbe ON bbe.buyer_id = bb.id
LEFT JOIN buy_buyer_extend_option bbeo_country ON bbe.id = bbeo_country.buyer_extend_id AND bbeo_country.code = 'country_code'
LEFT JOIN pub_dict_item country_code_pd ON bbeo_country.dict_item_id = country_code_pd.id
LEFT JOIN buy_buyer_extend_option bbeo_customer ON bbe.id = bbeo_customer.buyer_extend_id AND bbeo_customer.code = 'customer_type'
LEFT JOIN pub_dict_item customer_type_pd ON bbeo_customer.dict_item_id = customer_type_pd.id
WHERE
se.event IN ('click', 'purchase')
AND se.create_time >= DATE_SUB(NOW(), INTERVAL 7 DAY)
AND se.login_id IS NOT NULL
LIMIT 10;
|