Answer the question
In order to leave comments, you need to log in
How to filter data by counted count?
A simple query that runs without problems in MySql in Postgres gives an error. Request:
SELECT "t".*,
(SELECT COUNT(*) FROM "user_archive_view" WHERE user_tariff_id = t.id) AS "count_archive"
FROM "user_tariff" "t" HAVING "count_archive"='100';
Answer the question
In order to leave comments, you need to log in
HAVING is done before SELECT so it doesn't know anything about count_archive, here's a working one
SELECT "t".*,
(SELECT COUNT(*) FROM "user_archive_view" WHERE user_tariff_id = t.id) AS "count_archive"
FROM "user_tariff" "t"
HAVING (SELECT COUNT(*) FROM "user_archive_view" WHERE user_tariff_id = t.id) = '100';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question