在bigquery中追加结果查询

unftdfkk  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(320)

我正在做一个查询,其中查询将附加来自前一个日期的数据作为bigquery中的结果。因此,今天的结果数据将比昨天高,因为数据是按天追加的。到目前为止,我只得到了按天计算的数据(您可以看到id的数量在下降,并且没有从前一天追加),结果如下:

我应该怎么做才能在查询中添加附加函数,以便每天都能得到bigquery中前一天的数据结果?

code:
    WITH
    table1 AS (
    SELECT
         ID, 
      ...

       FROM t
       WHERE DATE_SUB('2020-01-31', INTERVAL 31 DAY) and '2020-01-31'
    ),

    table2 AS (
    SELECT 
        ID,
        COUNTIF((rating  < 7) as bad,
        COUNTIF((rating  >= 7 AND SAFE_CAST(NPS_Rating as INT64) < 9) as intermediate,
        COUNTIF((rating  as good

    FROM
        t
    WHERE DATE_SUB('2020-01-31', INTERVAL 31 DAY) and '2020-01-31'
    )

    SELECT  
    DATE_SUB('2020-01-31', INTERVAL 31 DAY) as date,
    * 
    FROM table1 
    FULL OUTER JOIN table2 USING (ID)
11dmarpk

11dmarpk1#

如果有要累加的计数,则需要累加和。查询如下所示:

select datecol, count(*), sum(count(*)) over (order by datecol)
from t
group by datecol
order by datecol;

相关问题