我现在进入BQ一周(对于我的硕士论文),经过几个小时的阅读文档后,我现在正挂在这一点上:
我使用censys Datasets并想要计算在国家'AT','DE','CH'打开端口的主机数量。到目前为止,我让它为每个国家本身工作。但是节省成本(也许)我想一次计算所有3个国家的费用。或者当我无法通过这种方法节省成本时,我可以继续使用我的第一个解决方案,并针对每个国家进行迭代。
目前一次为一个国家工作:
#standardsql
SELECT ports, count(ports) AS value FROM
(
SELECT ip, ports
FROM `censys-io.ipv4_public.20171231` i, i.ports
WHERE location.country_code LIKE 'AT'
)
GROUP BY ports
试图结合所有国家:
#standardsql
SELECT location.country_code, ports, count(ports) OVER ( PARTITION BY location.country_code) AS value FROM
(
SELECT location.country_code, ports
FROM `censys-io.ipv4_public.20171231` i, i.ports
WHERE location.country_code LIKE 'AT', 'DE', 'CH'
)
GROUP BY ports
它给了我(当我忽略6中的WHERE错误时):
Error: Unrecognized name: location at [2:8]
我不知道这是否是正确的方法,或者我是否应该使用其他功能。谢谢你的帮助!
以下是BigQuery Standard SQL
#standardsql
SELECT
country_code,
ports,
COUNT(ports) OVER ( PARTITION BY country_code, ports) AS value FROM
(
SELECT location.country_code, ports
FROM `censys-io.ipv4_public.20171231` i, i.ports
WHERE location.country_code IN ('AT', 'DE', 'CH')
)
GROUP BY country_code, ports
我现在知道了:
#standardsql
SELECT
country_code,
ports,
COUNT(ports) AS value FROM
(
SELECT location.country_code, ports
FROM `censys-io.ipv4_public.20171231` i, i.ports
WHERE location.country_code IN ('AT', 'DE', 'CH')
)
GROUP BY ports, country_code
删除了PARTITION BY。