SQL 查询:计数不同条件
SQL Query: Count Distinct with Condition
这是我的简化版 table:
is_clicked | direct_lead_id
------------+----------------
true | 4074448
false | 4074448
true | 4074448
我想 运行 对此进行查询,以便在 is_clicked = True 时获得 direct_lead_id 的不同计数。所以在这种情况下,我的查询结果将是 1。如果我在上面添加一行 table,假设:
真| 407449。
然后我想得到 2.
select count(distinct direct_lead_id )
from my_table
where is_clicked = true
这是我的简化版 table:
is_clicked | direct_lead_id
------------+----------------
true | 4074448
false | 4074448
true | 4074448
我想 运行 对此进行查询,以便在 is_clicked = True 时获得 direct_lead_id 的不同计数。所以在这种情况下,我的查询结果将是 1。如果我在上面添加一行 table,假设: 真| 407449。 然后我想得到 2.
select count(distinct direct_lead_id )
from my_table
where is_clicked = true