Доброго времени суток.
Есть такой sql код:
SELECT
"c"."title" AS "campaignName",
"c"."status" AS "status",
"country"."iso_code" AS "countryCode",
"fv"."definition" ->> 'name' AS "framework",
"u"."first_name" AS "manager",
"c"."client_id" AS "clientId",
"client"."name" AS "clientName",
COALESCE("members".COUNT,
0) AS "membersCount"
FROM "campaign" "c"
INNER JOIN "framework_version" "fv" ON "fv"."framework_id" = "c"."framework_version_id"
INNER JOIN "client" "client" ON "client"."id" = "c"."client_id"
INNER JOIN "country" "country" ON "client"."country_id" = "country"."id"
INNER JOIN "campaign_user" "campaignUser" ON "c"."id" = "campaignUser"."campaign_id"
AND "campaignUser"."role" = 'MANAGER'
AND "campaignUser"."user_enabled" = true
INNER JOIN "user" "u" ON "campaignUser"."user_id" = "u"."id"
LEFT JOIN
(SELECT "campaignUser"."campaign_id" AS "campaignId",
COUNT(*) AS "count"
FROM "campaign_user" "campaignUser"
GROUP BY "campaignUser"."campaign_id") "members" ON "members"."campaignId" = "c"."id"
GROUP BY "client"."id", "c"."title", "c"."status", "country"."iso_code", "fv"."definition", "u"."first_name", "c"."client_id", "members".COUNT
мне нужно избавиться от лишних group by и оставить только "client"."id"
но так же мне нужно что бы в "membersCount" записалось количество юзеров взяты по ид компаний из таблицы "campaignUser"
есть идеи как можно изменить данный запрос? За ранее благодарю!