简体   繁体   English

SQL 案例陈述when

[英]SQL case statement with case when

I have a question about SQL case statement.我对 SQL 案例陈述有疑问。 I have a table where 1 account can have multiple web ids(users coming from website) and app id (users coming from app).我有一张表,其中 1 个帐户可以有多个 web id(来自网站的用户)和应用程序 ID(来自应用程序的用户)。 the account id is unique.帐户 ID 是唯一的。 I want to identify accounts based on webuser and app users.我想根据网络用户和应用程序用户来识别帐户。 The case statement written is as follows写的case语句如下
(CASE WHEN (webid IS NULL AND appid is not null ) THEN 'App user' WHEN (appid IS NULL and webid is not null ) THEN 'Web user' ELSE 'Web and App user' END)
However the categorisation is not working correctly as it is categorsing 1 account as web user or app user as well as Web and App user.但是,分类无法正常工作,因为它将 1 个帐户分类为 web 用户或应用程序用户以及 Web 和应用程序用户。 How can I fix this issue?我该如何解决这个问题?

在此处输入图像描述

You seem to want to take the account_id into account as well:您似乎也想考虑account_id

(CASE WHEN AccountId IS NULL THEN NULL
      WHEN webid IS NULL AND appid is not null THEN 'App user'
      WHEN appid IS NULL AND webid is not null THEN 'Web user'
      ELSE 'Web and App user'
 END) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM