查询语句:
SELECT "count"(DISTINCT(data->>'Id')) from table1 where (data->>'Flag')::int = '1';
试一下9.4以上的,用jsonb
EXPLAIN SELECT "count"(DISTINCT(data->>'Id')) from table1 where (data->>'Flag')::int = '1';
看一下呢,请养成 EXPLAIN 的良好习惯。
不过我猜测可以通过加索引的方式来提高查询速度。