我有app_id,http_host列,该列由以下行组成:a-aa,a-bb,a-cc,b-hh。我想计算每个不同的http_host在app_id列中有多少不同的值。我想得到a-3,b-1
select app_id, http_host,
ROW_NUMBER() over (PARTITION by app_id order by app_id desc) as rowNum
FROM "public"."bus_request"
group by app_id, http_host
我以为它将按app_id进行分区,a将具有1,b将具有2,但这是不正确的。
答案 0 :(得分:0)
使用非重复计数
select app_id, count(distinct http_host)
from tablename
group by app_id
答案 1 :(得分:0)
使用非重复计数
select http_host,count(distinct app_id)
FROM "public"."bus_request"
group by http_host