[英]Postgresql how to find distinct values and count
I have a table with ID, data 1, and few other columns... data 1 has NA as well.我有一个带有 ID、数据 1 和其他几列的表……数据 1 也有 NA。
I need to find a distinct ID, followed by the total count of each ID and the count for each ID whose data has NA.我需要找到一个不同的 ID,然后是每个 ID 的总计数以及数据具有 NA 的每个 ID 的计数。 I need to determine how much of NA values are loaded for each ID.
我需要确定为每个 ID 加载了多少 NA 值。
Thanks Sai谢谢赛
select
id,
count(*) as total_count,
count(*) filter (where data1 = 'NA') as na_count
from _table
group by id;
You can use standard sql with conditional aggregation
as follows:您可以将标准 sql 与
conditional aggregation
一起使用,如下所示:
Select id, count(1) as total,
Count(case when data1='NA' then 1 end) as NA_count
From your_table
Group by id;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.