我有一个会话表,其中包含userId和访问主页的嵌套记录(字符串)以及一个会话中每次访问的时间戳。基本上一行中的1:m关系:
UserId|SessionEndTime|page1|timestamp1|
|page2|timestamp2|
|page1|timestamp3|
我想知道的是如何让所有在过去6个月内访问过我的网页6x的用户ID他们应该访问了网页(名称为'%astring%')at at至少2次。
这是我的方法,但我如何将类似的条件带入count()?:
SELECT UserId, COUNT(UserId) AS visitCounter FROM [oxidation.TestVisits]
WHERE SessionEndTime >= TIMESTAMP_TO_MSEC(DATE_ADD(CURRENT_TIMESTAMP(),-6,"MONTH"))
AND LastUserId != 'none'
GROUP BY 1
HAVING visitCounter>=6
ORDER BY 1 ASC
答案 0 :(得分:5)
将SUM(page LIKE '%astring%') AS pageCounter
添加到您的查询
SELECT UserId, COUNT(UserId) AS visitCounter,
SUM(page LIKE '%astring%') AS pageCounter
FROM [oxidation.TestVisits]
WHERE SessionEndTime >= TIMESTAMP_TO_MSEC(DATE_ADD(CURRENT_TIMESTAMP(),-6,"MONTH"))
AND LastUserId != 'none'
GROUP BY 1
HAVING visitCounter>=6
AND pageCounter >= 2
ORDER BY 1 ASC