我正在尝试获取唯一的ip_addresses数量(在这种情况下为’3′).该表如下所示:
结构体:
CREATE TABLE bandits ( key text NOT NULL,ip_address inet,offence text,count bigint DEFAULT 1);
数据:
COPY bandits (key,ip_address,offence,count) FROM stdin; 127.0.0.1_testing 127.0.0.1 testing 1 127.0.0.2_testing 127.0.0.2 testing 3 127.0.0.2_testing2 127.0.0.2 testing2 1 127.0.0.3_testing 127.0.0.3 testing 1
解决方法
SELECT COUNT(DISTINCT ip_address) FROM bandits