我不会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 < stargazers < 500。
我想:一次从多个类型值中获取数据: (对于谁感兴趣,请在此处找到类型的描述: https://developer.github.com/v3/activity/events/types/ )
我愿意:
- 根据 Type 字段中的其他变量获取数据,例如 pushEvents 和 downloadEvents
- 按 repo 协议(protocol)对推送和下载进行分组:如果一个 repo 协议(protocol)有来自一位用户的多次推送,则返回一行以减小结果表的大小。
- 获取项目的观星者数量,限制为 1
我尝试按 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.
您能否帮助理解我做错了什么,以便:
- 将所有提交给用户的 repo 推送收集到一个唯一的行中
- 一次收集类型字段中的更多事件(例如推送+下载+观看
可能我想将上述查询与应用于 WatchEvent 中涉及的用户数量的约束相结合: - 获取所有关注 repo 的星星(即 watchEvents 中的所有 actor_attributes_login),限制为 1
但最终我可以在后处理中完成最后一部分,以降低复杂性。 谢谢你的帮助!
最佳答案
也许我误解了您的问题陈述,但我认为以下 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;
关于mysql - 从 github_timeline : group pushes and downloads by repos, 中选择存储库 url 并通过 stargazers 过滤 repos,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28013010/