这是表格。
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)
)
我有 5000 条记录。我想要得到的是以下结果: 有 57 个摄像头,它们各不相同,但有 3 个相同,它们是
'external_http_port', config->> 'external_host', config-> 'snapshots'->> 'jpg'
我想创建一个查询,将结果显示为
external_http_port | external_host | config-> 'snapshots'->> 'jpg' | Count
"93.87.73.118" | "1024" | "/oneshotimage.jpg" | 57
"180.180.180.48" | "81" |"/onvif/media_service/snapshot"|20
最佳答案
这个呢?
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;
关于sql - PostgreSQL - 根据 3 列选择重复数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34352177/