【问题标题】:How to create a expression of ClickHouse countIf function for linq2db?如何为 linq2db 创建 ClickHouse countIf 函数的表达式?
【发布时间】:2022-12-17 08:39:26
【问题描述】:

如何将 clickhouse countIf 函数迁移到 linq2db?

例子:

来自 =>

SELECT customer_id,
   countIf(customer_id, active_month between 0 and 1) as active_month1
FROM myt_table
GROUP BY customer_id

到=>

from x in my_table
group x by x.customerId into g
select new {
    CustomerId = g.Key,
    ActiveMonth1 = Sql.CountIf(x, p => p.customerId, p => p.ActiveMonth.between(1, 6)) 
}

我试过这个选项,但它有问题

from x in MyTable
group x by x.CustomerId into g
select new {
    CustomerId = g.Key,
    FirstMonthCount = g.Count(p => 1 >= p.ActiveMonth && p.ActiveMonth <= 6)
}

【问题讨论】:

  • countIf(customer_id, active_month between 0 and 1) as active_month1 顺便说一句,它计算number of rows,其中条件为真且 customer_id 不为空。我猜你需要/意味着countIf(active_month between 0 and 1)

标签: countif clickhouse linq2db


【解决方案1】:

有什么理由不能用active_month 上的 WHERE 子句重写它并使用标准的count()

【讨论】:

    猜你喜欢
    • 2023-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-10
    • 2023-02-04
    • 1970-01-01
    相关资源
    最近更新 更多