add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Help with an interesting Postgres question: Why isn't an Index Only Scan used on a partition accessed via the parent table?.
CREATE TABLE departamentos (
id_departament int PRIMARY KEY
);
CREATE TABLE employees (
id_user int,
id_departament int REFERENCES departamentos (id_departament)
);

INSERT INTO departamentos VALUES (1),(2);
INSERT INTO employees VALUES (100,1),(83,1),(42,1),(88,2),(99,2);
CREATE TABLE
CREATE TABLE
INSERT 0 2
INSERT 0 5
SELECT d.id_departament, count(e.id_departament) AS TOTAL
FROM departamentos d
JOIN employees e ON e.id_departament = d.id_departament
GROUP BY d.id_departament
HAVING count(e.id_departament) > 2
id_departament total
1 3
SELECT 1