Skip to content

Instantly share code, notes, and snippets.

@MikeRzhevsky
Created May 6, 2022 18:46
Show Gist options
  • Save MikeRzhevsky/e5f818bf7961c92bcbf303d83ad98152 to your computer and use it in GitHub Desktop.
Save MikeRzhevsky/e5f818bf7961c92bcbf303d83ad98152 to your computer and use it in GitHub Desktop.
with t as (select date,
clientid,
arrayJoin(JSONExtract(assumeNotNull(hour_info),'Array(String)')) as hour,
arrayJoin(extractAll(assumeNotNull(productSku),'"(\\w+)"')) as product
from {{ ref("src_for_web_sessions") }})
select CAST(t.date as Date) as "Дата", t.hour as "Час", item.`ссылка` as "Товар", count(*) as "Количество просмотров" from t
join (select * from {{source('bq','`cifra_товары`')}} ) as item on item.`код sku` = t.product
group by t.date, t.hour, item.`ссылка`, t.clientid
UNION ALL
select CAST(t.date as Date) as "Дата", t.hour as "Час", item.`ссылка` as "Товар", count(*) as "Количество просмотров" from t
join (select * from {{source('bq','`cifra_товары`')}} limit 1 by `код группы sku`) as item on item.`код группы sku` = t.product
group by t.date, t.hour, item.`ссылка`, t.clientid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment