【发布时间】:2018-03-09 18:52:04
【问题描述】:
我有一个查询,当用户向购物车中添加商品时,它会跟踪购物车中的商品。我已经完成了添加项目的部分,但我无法根据给定的操作删除单个项目。这是一个例子:
SELECT
*,
-- Remove item from cart where item in cart
CASE WHEN cart_action = 'remove from cart' THEN (SELECT SPLIT(cart, ',') - SPLIT(cart, ',') WHERE SPLIT(cart, ',') = item)
FROM
(
SELECT
'remove from cart' AS cart_action,
'apple' AS item,
'apple, orange, banana, apple' AS cart
);
如果我的购物车以'apple, orange, banana, apple' 开头,那么我希望输出为'orange, banana, apple'。物品的顺序无关紧要。
我希望能够将购物车字符串分解为一个数组,在数组中找到一个匹配的项目,删除该项目,然后返回更新后的购物车。
【问题讨论】:
标签: sql google-analytics google-bigquery