我不知道sql,我试图记录我自己,但无法达到我想要的结果。
我在Bigquery上查看此查询,针对Github_timeline:
SELECT repository_url, actor_attributes_login
FROM [githubarchive:github.timeline]
WHERE type='WatchEvent' AND actor_attributes_login IN (
SELECT actor_attributes_login FROM [githubarchive:github.timeline]
WHERE type='WatchEvent'
GROUP BY actor_attributes_login HAVING (count(*) > 1) AND (count (*) < 500)
)
GROUP EACH BY repository_url, actor_attributes_login;
在此处找到:https://github.com/anvaka/ghindex
根据我的理解,查询约束导致repos with 1&lt;观星者&lt; 500。
我想:从一个类型的多个值中一次获取数据: (对于有趣的人,请在此处找到类型的描述: https://developer.github.com/v3/activity/events/types/)
我想:
我尝试按照repository_url对行进行分组,然后是限制为1的观星者
SELECT repository_url, actor_attributes_login, type
FROM [githubarchive:github.timeline]
WHERE (type='PushEvent'OR type='WatchEvent') AND actor_attributes_login IN (
SELECT repository_url, actor_attributes_login FROM [githubarchive:github.timeline]
WHERE (type='WatchEvent' or type='PushEvent')
GROUP BY repository_url, actor_attributes_login HAVING (count(*) > 1) AND (count (*) < 500)
)
GROUP EACH BY repository_url, actor_attributes_login, type
LIMIT 100;
但得到了错误:
Error: Right query in semi-join must have exactly one field selected.
我还尝试从字段TYPE简化和收集多个变量,而不尝试按repository_url分组; (这里我只使用AND actor_attributes_login =='author'来限制结果数量,作为测试):
SELECT repository_url, actor_attributes_login, type
FROM [githubarchive:github.timeline]
WHERE (type='WatchEvent') AND actor_attributes_login IN (
SELECT actor_attributes_login FROM [githubarchive:github.timeline]
WHERE (type='WatchEvent' OR type='PushEvent' OR type='DownloadEvent' OR type='IssueCommentEvent') AND actor_attributes_login=='author'
GROUP BY actor_attributes_login HAVING (count(*) > 1) AND (count (*) < 500)
)
GROUP EACH BY repository_url, actor_attributes_login, type LIMIT 100;
可是:
Query returned zero records.
你可以帮助理解我做错了什么,以便:
可能我想将上述查询与应用于WatchEvent中涉及的用户数量的约束结合起来: - 获取所有注视回购的明星(即watchEvents中的所有actor_attributes_login),约束为1
但最终我可以在后期处理中做最后一部分,以降低复杂性。 谢谢你的帮助!
答案 0 :(得分:2)
也许我误解了你的问题陈述,但我认为以下SQL会做你想要的:
SELECT a.repository_url, a.actor_attributes_login, a.type
FROM [githubarchive:github.timeline] a
JOIN EACH
(SELECT actor_attributes_login FROM [githubarchive:github.timeline]
WHERE type IN ('WatchEvent', 'PushEvent')
GROUP BY actor_attributes_login HAVING (count(*) BETWEEN 1 AND 500)
) b
ON a.actor_attributes_login = b.actor_attributes_login
GROUP EACH BY 1,2,3 LIMIT 100;