错误:无法识别的名称:Google BigQuery

时间:2018-03-30 09:36:24

标签: sql google-bigquery

我是SQL的新手,我正试图在Google BigQuery中进行查询,如下所示:

 SELECT client, begindate, enddate, 
 LAG(enddate,1) OVER (PARTITION BY client ORDER BY begindate, 
 client) AS lag,
 ROUND(DATE_DIFF(DATE(begindate), lag, DAY)) as diff
 FROM
 db LIMIT 100;

但是它给出了错误“错误:无法识别的名称:滞后于......”

我真的不明白代码有什么问题;在数据集预览中,我看到成功创建了新列“滞后”(当我删除date_diff代码时)。那么为什么“滞后”是一个无法识别的名字?

1 个答案:

答案 0 :(得分:3)

试试这个:

SELECT client,begindate, enddate,lag,
ROUND(DATE_DIFF(DATE(begindate), lag, DAY)) as diff
FROM (
      SELECT client, begindate, enddate, 
      LAG(enddate,1) OVER (PARTITION BY client ORDER BY begindate, 
      client) AS lag, 
      FROM
      db LIMIT 100;
     ) AS t