当两个条件都是正确的时如何使用案例语句,您只需要显示一个条件
查询:
SELECT
DISTINCT userId,
sessionId,
CASE
WHEN b.pageType = 'confirm' THEN 'User_converted'
ELSE
'Not_converted'
END
AS conversion_index
FROM (
SELECT
userId,
sessionId,
p.createdat page_time,
p.pageType
FROM
ccart.sessv6_79633508 AS sess,
UNNEST(pages)p
WHERE
sess.createdAt >= TIMESTAMP('2021-07-01')
AND sess.createdAt <= TIMESTAMP ('2021-10-11')
AND userId = '206885636.2915067519'
AND sessionId = 'GH178U' )b
我尝试了此查询,我希望结果为“是或否”字段conversion_index
,但是由于给定用户两个语句都是正确的,因此
我想要的只是我想要的两个行是,如果页面类型='确认'确认'条件是正确的,那么返回值作为“是”否
query:
SELECT
DISTINCT userId,
sessionId,
CASE
WHEN b.pageType = 'confirm' THEN 'User_converted'
ELSE
'Not_converted'
END
AS conversion_index
FROM (
SELECT
userId,
sessionId,
p.createdat page_time,
p.pageType
FROM
ccart.sessv6_79633508 AS sess,
UNNEST(pages)p
WHERE
sess.createdAt >= TIMESTAMP('2021-07-01')
AND sess.createdAt <= TIMESTAMP ('2021-10-11')
AND userId = '206885636.2915067519'
AND sessionId = 'GH178U' )b
I have tried this query and I want result as yes or No for field conversion_index
but as both statements are true for a given user, hence two rows are appearing
All I want is if page type = 'confirm' condition is true, then return value as 'yes' else No
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果用户已经看到了页面类型='确认'甚至一次,则值应该为'是',否则“否”:
如果您想为每个用户最多2行(一个是对另一个用户),请尝试移动原始情况表达查询的一个“图层”:
因此,如果所有用户页面的全部是
p.pageType ='确认'
,您将获得是YES 仅限,如果所有用户页面的全部 不是p.pagetype ='确认'
您只会获得 no ,否则您将获得一行是,该用户的另一行否。If user has seen page type = 'confirm' even once, then value should be 'Yes', otherwise 'No':
If you wanted up to 2 rows for each user (one for Yes the other for No) try moving the original case expression down one "layer" of the query:
So if all for a user pages are
p.pageType = 'confirm'
you would get Yes only, if all for a user pages are notp.pageType = 'confirm'
you would get No only, otherwise you get one row Yes and another row No for that user.