Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sbsB2-0025En-Mg for pgsql-general@arkaria.postgresql.org; Thu, 08 Aug 2024 01:42:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sbsB1-00BB6p-44 for pgsql-general@arkaria.postgresql.org; Thu, 08 Aug 2024 01:42:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sbsB0-00BB6g-P2 for pgsql-general@lists.postgresql.org; Thu, 08 Aug 2024 01:42:50 +0000 Received: from mail-oo1-xc36.google.com ([2607:f8b0:4864:20::c36]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sbsAy-003ilh-P4 for pgsql-general@lists.postgresql.org; Thu, 08 Aug 2024 01:42:50 +0000 Received: by mail-oo1-xc36.google.com with SMTP id 006d021491bc7-5d5aecbe0a9so285727eaf.1 for ; Wed, 07 Aug 2024 18:42:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723081367; x=1723686167; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=nUp/5AD4nbxD1+XHPZAY4Nee59V7j2ho8MTBqWH8iSo=; b=OIRxYgdiJPtbmi6K/r9ke+V7w/gyv3e4g9mYntApdck74z2xAnD9Q8P/p1W56hHitc SNrtg56MYvPeQHoHQ67iBiachXF7+eB1bWG0Ja38noDZEH8uJSwdw/VppQJNzbVPU1BO Q6MaUTFBdIrJAGv01BAPdmCn6RREh/lLHECSXMpHSxpz7SFvJA+QqEtCiDjhV8b5BXEv UHDQ+kK9UrnNZHcDb45Ag5D+FEyB785aD9M/Gv8aaAp8kRWAVYNspNzL4XAfzif+BuAQ WehghpuRg3wgZAOgtV4zgxPV0iBxAcRSacUZttNir/bz3AnSzxg3nVj9IGZYrVvaEASl wMPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723081367; x=1723686167; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nUp/5AD4nbxD1+XHPZAY4Nee59V7j2ho8MTBqWH8iSo=; b=ZuoeIbGK827dAqYB14KKUA3MVnpCs7TzlJVlbNhyMdeJ9skFG+VL/2pK5t2K13K4Yq 8W7i/aytkGTAz+AYns+cuu6SpPT/Mo4GRmUYOfnOa7IoL27fxhdz+ZjaXoVuuAbKP+bM 661G7dtSZDHd/jsIT82zepsk2falZmaWHRrI4bdCllPPUHvtobgPq0hmT8WPfHryhG1k gOkzxVl26iN4jyrjBAXuGLCqh0sJj/SVZETQUwngFyeRncFAx/RRqwv+HgpK122bSeoR NznW13ic6wqDtMGkQSo/xFW22sVxDjl4Rhh85UgjX6zIZ4/BRqNThq/08UCwkf7zzaxZ RMTg== X-Gm-Message-State: AOJu0Yw6SW4huI4wivkbgJvd2IJ7ZV8tx+2JzFUfNAjBOBVWc3Qfq3cd Xu8y7EVQtCGCNQi7yRnqx9YB857Vhszs4qnLSZpkuhBRPESuImWyX/fZQ62sR+g3WjgtLBsS1k+ VZBDeU4UWxrNqF4YF3YxPsgYTRqbxqLVu X-Google-Smtp-Source: AGHT+IGgKVEb98LGsBroXPs+0OlO8GnnEhi5jjeMZ/uWND17st74Ks8aJTsZQEXP8SIWoj+DU+Usp9AJeAujAaLjiy4= X-Received: by 2002:a05:6820:270f:b0:5c4:57b6:ffbf with SMTP id 006d021491bc7-5d85576465cmr510143eaf.0.1723081367019; Wed, 07 Aug 2024 18:42:47 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a8a:c86:0:b0:557:c384:fb61 with HTTP; Wed, 7 Aug 2024 18:42:46 -0700 (PDT) In-Reply-To: References: From: "David G. Johnston" Date: Wed, 7 Aug 2024 18:42:46 -0700 Message-ID: Subject: Re: How can I get a query-based subtotal in a select using group by rollup ? To: dfgpostgres Cc: "pgsql-general@lists.postgresql.org" Content-Type: multipart/alternative; boundary="000000000000ccea95061f2224f5" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000ccea95061f2224f5 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wednesday, August 7, 2024, dfgpostgres wrote: > > (select > domain_name, > sum(total_tests) as total_tests, > sum(tests_completed) as tests_completed, > sum(tests_passed) as tests_passed, > sum(tests_failed) as tests_failed, > (select count(*) from dispatch_tracker where > regression_name=3Drt.regression_name and domain_name=3Drt.domain_name and > dispatch_status=3D'Y') as dispatched > from > regr.dispatch_tracker rt where rt.regression_name=3D'2024_08_ > 02_10_32_53_soundwave__er_common_regression__CL2017473_z1_soundwave_adm' > group by rollup(rt.domain_name) order by rt.domain_name ASC NULLS LAST) > d; > Either add regression_name to the group by as the error hints at you, or since you are already grouping implicitly by that (by virtue of the where clause filter) and domain_name just count the number of dispatch_status=3DY in the group: count(*) filter (where dispatch_status =3D =E2=80=98Y=E2=80= =99) The option that avoids the subquery is arguably better. Though I=E2=80=99d probably still include the regression_name in the output anyway - why hide what you are filtering on. David J. --000000000000ccea95061f2224f5 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wednesday, August 7, 2024, dfgpostgres <dfgpostgres3@gmail.com> wrote:

=C2=A0 (select
=C2=A0 =C2= =A0 domain_name,
=C2=A0 =C2=A0 sum(total_tests) as total_tests,
=C2= =A0 =C2=A0 sum(tests_completed) as tests_completed,
=C2=A0 =C2=A0 sum(te= sts_passed) as tests_passed,
=C2=A0 =C2=A0 sum(tests_failed) as tests_fa= iled,
=C2=A0 =C2=A0 (select count(*) from dispatch_tracker where regressi= on_name=3Drt.regression_name and domain_name=3Drt.domain_name and disp= atch_status=3D'Y') as dispatched
=C2=A0 from
= =C2=A0 =C2=A0 regr.dispatch_tracker rt where =C2=A0rt.regression_name=3D= 9;2024_08_02_10_32_53_soundwave__er_common_regression__CL2017473_= z1_soundwave_adm'
=C2=A0 group by rollup(rt.domain_name) order = by rt.domain_name ASC NULLS LAST) d;

Either add regression_name to the group by as the error hints at you,= or since you are already grouping implicitly by that (by virtue of the whe= re clause filter) and domain_name just count the number of dispatch_status= =3DY in the group: =C2=A0count(*) filter (where dispatch_status =3D =E2=80= =98Y=E2=80=99)

The option that avoids the subquery= is arguably better.=C2=A0 Though I=E2=80=99d probably still include the re= gression_name in the output anyway - why hide what you are filtering on.

David J.

--000000000000ccea95061f2224f5--