我使用此查询从用户已达到的最高章节中拉出最高级别的遭遇:
SELECT COUNT(hc.s) as users, highest_chapter, highest_encounter
FROM
(
SELECT s, MAX(l) as highest_chapter
FROM appl9_evt
WHERE month = "201508" AND st1 = "player" AND st2 = "level_progression" AND n = "level_start"
GROUP BY s
ORDER BY highest_chapter
) hc
INNER JOIN
(
SELECT s, l, MAX(get_json_object(json_data, '$.CurrentEncounter')) as highest_encounter
FROM appl9_evt
WHERE month = "201508" AND st1 = "player" AND st2 = "level_progression" AND n = "level_start"
GROUP BY s, l
ORDER BY highest_encounter
) he ON hc.s = he.s AND hc.highest_chapter = he.l
GROUP BY highest_chapter, highest_encounter
然后我把它保存为一个表,并尝试只获得版本2.2.1(或任何版本,我认为它被称为自我加入):
SELECT COUNT(DISTINCT highest.s) as users, highest_chapter, highest_encounter FROM
(
SELECT users as s, highest_chapter, highest_encounter
FROM augusers221
) highest
INNER JOIN
(
SELECT s
FROM appl9_cpu
WHERE v_maj = '2.2.1'
) ver ON highest.s = ver.s
GROUP BY highest_chapter, highest_encounter
ORDER BY highest_chapter, highest_encounter
但是第二阶段出现了问题,因为我无法提取任何数据......请提前感谢您查看此文本墙。
答案 0 :(得分:0)
我无法确定没有样本数据且列名不友好。但似乎s
列包含用户名或ID。是对的吗?
如果是这样,那么您无法将其加入augusers221.users
列,因为它是一个用户数。
您可以在第一个查询中加入appl9_cpu
表,我认为您需要,因为您在第二次查询时已经丢失了用户名/ ID。< / p>
SELECT COUNT(hc.s) as users, highest_chapter, highest_encounter
FROM
(
SELECT s, MAX(l) as highest_chapter
FROM appl9_evt
WHERE month = "201508" AND st1 = "player" AND st2 = "level_progression" AND n = "level_start"
GROUP BY s
ORDER BY highest_chapter
) hc
INNER JOIN
(
SELECT s, l, MAX(get_json_object(json_data, '$.CurrentEncounter')) as highest_encounter
FROM appl9_evt
WHERE month = "201508" AND st1 = "player" AND st2 = "level_progression" AND n = "level_start"
GROUP BY s, l
ORDER BY highest_encounter
) he ON hc.s = he.s AND hc.highest_chapter = he.l
INNER JOIN appl9_cpu cpu ON cpu.s = hc.s
WHERE cpu.v_maj = '2.2.1'
GROUP BY highest_chapter, highest_encounter
如果这没有帮助,那么也许您可以发布一些样本数据。
答案 1 :(得分:0)
从我所看到的这个小提琴:http://sqlfiddle.com/#!9/1026d/3
问题是由于SELECT COUNT(hc.s) as users,
稍后将其加入s
中的ON highest.s = ver.s
时导致的。所以,你加入计数到实际价值。
如果您将列名更改为更明确,则问题可能更清楚。