不确定是否可以,但是我有一个如下表:
URL | amount | date | ...........
值URL可以是如下所示的URL:
https://www.example.com/category1/subcategory1/....... | 1243 | 01-01-1999
https://www.example.com/category1/subcategory2/....... | 4325 | 01-02-1999
https://www.example.com/category1/subcategory2/....... | 23 | 01-02-1999
https://www.example.com/category2/subcategory1/....... | 12543 | 01-01-1999
https://www.example.com/category2/subcategory2/....... | 124453 | 01-01-1999
如何获得对查询中已经存在的URL进行分组/分类的结果?我正在寻找的结果是:
category1 | average(amount) | 01-01-1999
category1 | average(amount) | 01-02-1999
category2 | average(amount) | 01-01-1999
使用Google BigQuery并查找可以执行此操作的示例查询。
答案 0 :(得分:1)
以下是用于BigQuery标准SQL
#standardSQL
SELECT
REGEXP_EXTRACT(url, CONCAT(r'', NET.REG_DOMAIN(url), '/([^/]*)/')) AS category,
AVG(amount) AS avg_amount, date
FROM `project.dataset.table`
GROUP BY category, date
注意,以上解决方案还涵盖了以下情况
www.example.com/category2/subcategory2/......., 124453, '01-01-1999'
答案 1 :(得分:0)
如果我们将网址除以'/'
,那么这似乎是第四个元素。所以:
select split(url, '/')[ordinal(4)] as category, date, avg(amount)
from t
group by category, date;
答案 2 :(得分:0)
declare @t table (category varchar, amount bigint, date date)
insert into @t
select f_findSring(column1) -- this function returns category1, category2 and so...
,amount
,date
select category
,average(amount)
,date
from @t
group by category, date