加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql – 如何计算唯一值?

发布时间:2020-12-12 16:56:08 所属栏目:MsSql教程 来源:网络整理
导读:我正在尝试获取唯一的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;1
我正在尝试获取唯一的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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读