函数的BigQuery SQL语法错误(“语法错误:应为”);但在[7:18]时得到了关键字“的”

函数的BigQuery SQL语法错误(“语法错误:应为”);但在[7:18]时得到了关键字“的”,sql,google-bigquery,Sql,Google Bigquery,我需要根据dev_id将数据连接到一个列(cont_url)中。我能够通过这个查询在MS-SQL中成功地做到这一点,但我需要在BigQuery中做到这一点 select dev_id, stuff( (SELECT '|||' + cont_url FROM `test_table_sample` WHERE dev_id = a.dev_id FOR XML PATH ('')) --Erro

我需要根据dev_id将数据连接到一个列(cont_url)中。我能够通过这个查询在MS-SQL中成功地做到这一点,但我需要在BigQuery中做到这一点

select
    dev_id,
    stuff(
    (SELECT '|||' + cont_url
      FROM `test_table_sample`
        WHERE  dev_id = a.dev_id
         FOR XML PATH (''))                --Error is here
        , 1, 1, '') as testlist
from
    `test_table_sample` as a
group by
    dev_id
当我在大查询中挂载表并尝试运行相同的查询时,会出现语法错误

应为“)”但在[7:18]获得了关键字

我不知道我做错了什么,也不知道BigQuery标准SQL语法与T-SQL有何不同

我已经包括了一个数据样本表

test_table_sample
dev_id  cont_url
Device1 Link1
Device1 Link2
Device1 Link3
Device1 Link4
Device2 anotherLink1
Device2 anotherLink2
Device2 anotherLink3
Device2 anotherLink4
Device2 anotherLink5
以下是查询结果

Results 
dev_id  cont_url
Device1 Link1|||Link2|||Link3|||Link4
Device2 anotherLink1|||anotherLink2|||anotherLink3|||anotherLink4|||anotherLink5

BigQuery允许您只聚合字符串。语法要简单得多:

select dev_id, string_agg(cont_url, '|||') as testlist
from `test_table_sample` as a
group by dev_id;
尽管如此,我强烈建议您改用数组:

select dev_id, array_agg(cont_url) as testlist
from `test_table_sample` as a
group by dev_id;

比笨拙的分隔字符串要好得多。

BigQuery允许您只聚合字符串。语法要简单得多:

select dev_id, string_agg(cont_url, '|||') as testlist
from `test_table_sample` as a
group by dev_id;
尽管如此,我强烈建议您改用数组:

select dev_id, array_agg(cont_url) as testlist
from `test_table_sample` as a
group by dev_id;

比笨拙的分隔字符串要好得多。

您好,非常感谢您的回答。我想没有办法将url数据放在一个单元格中(我将计算唯一的用户路径,并希望每个用户的所有链接都放在一个单元格中)@Putnik
string_agg()
执行您在SQL Server中明确执行的操作
array\u agg()
可能更可取。如果您好奇,请同时使用这两种方法!他们使用相同的聚合。嗨,非常感谢你的回答。我想没有办法将url数据放在一个单元格中(我将计算唯一的用户路径,并希望每个用户的所有链接都放在一个单元格中)@Putnik
string_agg()
执行您在SQL Server中明确执行的操作
array\u agg()
可能更可取。如果您好奇,请同时使用这两种方法!它们使用相同的聚合。