【问题标题】:Get null value after filled value in SQL在 SQL 中填充值后获取空值
【发布时间】:2022-12-03 03:06:48
【问题描述】:

在拥有有效的潜在客户来源后,我需要计算帐户 ID 列中有多少记录在潜在客户来源列中具有空值(有效的潜在客户来源只是潜在客户来源不为空)

有相同的帐户 ID 并且存在值 null 和不为 null 我需要计数值 null 存在另一个不为 null 的值。 Table that exists values null and not null for same account ID

我尝试使用 CTE 和子查询,但无法达到预期的结果。

【问题讨论】:

  • 你能分享一下你的预期份额吗
  • 我需要计算第一个值 AccountID 不为空且第二个值为空的所有值。例如:帐户 |铅 123 | 37464 123 | NULL 我需要在第一个值不为 null 之后计算所有值,即 null

标签: sql count databricks


【解决方案1】:

试试这个查询:

select account_id,
sum(case when leadsource is null then 1 else 0 end) as null_count,
sum(case when leadsource is not null then 1 else 1 end) as not_null_count
from table_name group by account_id

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-20
    • 1970-01-01
    • 1970-01-01
    • 2015-09-17
    • 2021-09-30
    • 2017-07-19
    相关资源
    最近更新 更多