mysql - BigQuery: Consolidate subselect into one row by date -
i'm trying have bigquery query result, contains subquery, return 1 row instead of two. i'm querying log files data need in same field. example of data in field follow:
/?cv=p15.0.9350&ctyp=sp&bits=64&os_bits=64&hl=fr&hl=fr&os=win&osv=6.2
the query i've been working on below:
select day, win, mac (select date(metadata.timestamp) day, count(distinct protopayload.resource) win [su_dashboard_streamed_logs.appengine_googleapis_com_request_log_20150424] protopayload.resource contains 'ctyp=sp' group day), (select date(metadata.timestamp) day, count(distinct protopayload.resource) mac [request_log_20150424] protopayload.resource contains 'ctyp=sm' group day) order day
currently query above returns:
row day win mac 1 2015-04-24 160516 null 2 2015-04-24 null 109547
i'd result be:
row day win mac 1 2015-04-24 160516 109547
is there way this? if so, appreciated.
thank you
you want join
2 sub-selects instead of unioning them. in bigquery, a comma within from
clause indicates union:
note: unlike many other sql-based systems, bigquery uses comma syntax indicate table unions, not joins.
if join
on day field, can compact 2 rows single 1 following:
select table_1.day day, table_1.win win, table_2.mac mac (select date(metadata.timestamp) day, count(distinct protopayload.resource) win [su_dashboard_streamed_logs.appengine_googleapis_com_request_log_20150424] protopayload.resource contains 'ctyp=sp' group day) table_1 join (select date(metadata.timestamp) day, count(distinct protopayload.resource) mac [request_log_20150424] protopayload.resource contains 'ctyp=sm' group day) table_2 on table_1.day = table_2.day order day
Comments
Post a Comment