我的参考是Transpose rows into columns in BigQuery (Pivot implementation)
我尝试通过用string_agg替换group_concat_unquoted来在标准的大查询中实施建议,但是我没有成功使用正确的语法和结构。
WITH
input AS (
SELECT
user_pseudo_id AS user_id,
event_timestamp,
p.key AS key,
p.value.string_value AS value
FROM
`myproject.analytics_xxxx.events_*`,
UNNEST(event_params) AS p
WHERE
AND event_name = 'event_type_to_pivot' )
SELECT
'select user_id, ' + STRING_AGG(
'MAX(IF(key = "'+key+'", value, NULL)) as ['+key+']'
) + 'FROM input group by user_id order by user_id'
FROM (
SELECT
key
FROM
input
GROUP BY
key
ORDER BY
key )
我总是遇到错误: 对于参数类型:STRING,STRING,运算符+没有匹配的签名。支持的签名:INT64 + INT64; FLOAT64 + FLOAT64; NUMERIC + NUMERIC在[19:3]行:
STRING_AGG(
'MAX(IF(key = "'+key+'", value, NULL)) as ['+key+']'
)
经过大量尝试,我仍然不了解如何正确使用string_agg将行转置为列。
感谢您的指导,
答案 0 :(得分:0)
在#standardSQL中,使用private function getDataHelper(Request $request)
{
$message = new Message([
'title' => $request->get('title'),
'description' => $request->get('description'),
'branch_id' => Auth::user()->branch_id,
'user_id' => Auth::user()->id
]);
$title = $request->get('title');
$description = $request->get('description');
if($title === 'products' || $description === 'products') {
return redirect('getproducts');
}
if($title === 'customer' || $description === 'customer') {
return redirect('getcustomer');
}
if($title === 'shop' || $description === 'shop') {
return redirect('getshop');
}
// otherwise redirect home
return redirect('/');
}
代替CONCAT()
来组成字符串:
+