sql - Hits per day in Google Big Query -


i using google big query find hits per day. here query,

select count(*) key,         date(eventdateutc) value     [mydataset.mytable]     .....  group value  order value desc  limit 1000; 

this working fine ignores date 0 hits. wanna include this. cannot create temp table in google big query. how fix this.

tested getting error field 'day' not found.

select count(*) key,         date(t.day) value  (        select date(date_add(day, i, "day")) day  (select '2015-05-01 00:00' day)  cross join (select     position(      split(        rpad('', datediff(current_timestamp(),'2015-05-01 00:00')*2, 'a,')))   (select null)) b         ) d left join [sample_data.requests] t on d.day = t.day group value  order value desc  limit 1000; 

you can query data exists in tables, query cannot guess dates missing table. problem need handle either in programming language, or join numbers table , generates dates on fly.

if know date range have in query, can generate days:

select date(date_add(day, i, "day")) day  (select '2015-01-01' day)  cross join (select     position(      split(        rpad('', datediff('2015-01-15','2015-01-01')*2, 'a,')))   (select null)) b; 

then can join result query table:

select count(*) key,         date(t.day) value  (...the.above.query.pasted.here...) d left join [mydataset.mytable] t on d.day = t.day    .....  group value  order value desc  limit 1000; 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -