SQL查询:计数与条件不同

时间:2021-09-18 15:41:28

This is my simplified table:

这是我的简化表:

 is_clicked | direct_lead_id 
------------+----------------
 true       |        4074448 
 false      |        4074448 
 true       |        4074448

I would like to run a query on this to get a distinct count of the direct_lead_id when is_clicked = True. So the result of my query would be 1 in this case. If I added a line to the above table, let say: true| 407449. Then I would want to get 2.

我想对此运行一个查询,以便在is_clicked = True时获得direct_lead_id的明确计数。因此,在这种情况下,我的查询结果为1。如果我在上表中添加一行,请说:true | 407449.然后我想得到2。

1 个解决方案

#1


3  

select count(distinct direct_lead_id ) 
from my_table
where is_clicked = true

#1


3  

select count(distinct direct_lead_id ) 
from my_table
where is_clicked = true