我不懂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
根据我的理解,查询约束结果是以1<观星者<500.
我想:在一次拍摄中从Type的多个值中获取数据:(对于感兴趣的人,请在此处找到类型描述:https://developer.github.com/v3/activity/events/types/)
我想:
- 根据Type字段中的其他变量获取数据,例如pushEvents和downloadEvents
- 按repo对推送和下载进行分组:如果repo有来自一个用户的多个推送,则返回一行以减小生成的表的大小
- 获取一个项目的观星者数量,限制为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;