gpt4 book ai didi

mysql - 使用 CASE 的 SQL 查询

转载 作者:行者123 更新时间:2023-11-29 17:51:15 25 4
gpt4 key购买 nike

Hi need query to get the email1Opened and email1Sent i.e yes/no for email_type 1 in a single row. Not on multiple rows.

我正在写入查询以获取 email1Opened 和 email1Sent,即单行中 email_type 1 的 yes/no。不在多行上。那么你能帮我单行打印吗?

select user_id, 
business_id,
email_status,
id, email_type,
case when email_status='open' and email_type = 1 then 'YES' else 'NO' end email1Opened,
case when email_status='Sent' and email_type = 1 then 'YES' else 'NO' end email1Sent
from email_track where business_id = 10;

最佳答案

如果您只想获取 email_type 1,则应在查询中使用另一个 where:

select user_id, 
business_id,
email_status,
id, email_type,
case when email_status='open' then 'YES' else 'NO' end as email1Opened,
case when email_status='Sent' then 'YES' else 'NO' end as email1Sent
from email_track where business_id = 10 and email_type = 1;

关于mysql - 使用 CASE 的 SQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49315290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com