【发布时间】: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