PostgreSQL - 根据3列选择重复数据

时间:2015-12-18 09:20:08

标签: sql postgresql

这是表格。

!important

我有5000条记录。我想要得到的是以下结果: 有57个相机,它们各有不同,但有3个相同,都是

CREATE TABLE cameras
(
  id integer NOT NULL DEFAULT nextval('sq_streams'::regclass),
  created_at timestamp with time zone NOT NULL DEFAULT now(),
  updated_at timestamp with time zone NOT NULL DEFAULT now(),
  exid text NOT NULL,
  owner_id integer NOT NULL,
  is_public boolean NOT NULL,
  config json NOT NULL,
  name text NOT NULL,
  last_polled_at timestamp with time zone DEFAULT now(),
  is_online boolean,
  timezone text,
  last_online_at timestamp with time zone DEFAULT now(),
  location geography(Point,4326),
  mac_address macaddr,
  model_id integer,
  discoverable boolean NOT NULL DEFAULT false,
  preview bytea,
  thumbnail_url text,
  CONSTRAINT pk_streams PRIMARY KEY (id)
)

我想创建一个查询,将结果显示为

'external_http_port', config->> 'external_host', config-> 'snapshots'->> 'jpg'

2 个答案:

答案 0 :(得分:1)

这是怎么回事?

SELECT config ->>'external_http_port' AS external_http_port, 
       config->> 'external_host' AS external_host, 
       config-> 'snapshots'->> 'jpg' AS snapshots,
       count(*) 
FROM cameras  
GROUP BY config->>'external_http_port', config->> 'external_host', config-> 'snapshots'->> 'jpg' 
HAVING count(*) > 1;

答案 1 :(得分:0)

它能解决这个问题吗? (想象一个类比,而不是文字)

double units