简体   繁体   English

SQL查询:计数与条件不同

[英]SQL Query: Count Distinct with Condition

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. 我想对此运行查询,以便在is_clicked = True时获得direct_lead_id的明确计数。 So the result of my query would be 1 in this case. 因此,在这种情况下,我的查询结果为1。 If I added a line to the above table, let say: true| 如果我在上表中添加了一行,请说:true | 407449. Then I would want to get 2. 407449.然后我想得到2。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM