Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p3jCJ-0000kx-AM for pgsql-sql@arkaria.postgresql.org; Fri, 09 Dec 2022 19:38:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p3jCH-0007Cg-Td for pgsql-sql@arkaria.postgresql.org; Fri, 09 Dec 2022 19:38:13 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p3jCH-0007CX-JW for pgsql-sql@lists.postgresql.org; Fri, 09 Dec 2022 19:38:13 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p3jCF-0005VV-Ck for pgsql-sql@lists.postgresql.org; Fri, 09 Dec 2022 19:38:12 +0000 Received: by mail-pj1-x1029.google.com with SMTP id u5so5796682pjy.5 for ; Fri, 09 Dec 2022 11:38:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=QPjoY8ZbuoqomqizwrDxTKQEKSvTaRluAswzIwRCQRs=; b=qvWJRmf7uaR1aXwzjTRu5jm0Np7U94sFzzt3S98+UP22edo2fZ5mTxAthWqrRkYINV jp7gr+D2KEgjUWTuPVKEKQ+6QHySsLffyZA20oY5o1jo3aYSGQQ1OnUkxMfK+gbg3bWK TbJwvsKyT1/mANgq8hESGf0aDdC2eOKhfIJ85o8SmO5opbJpXdWj70gGIBqjDra3PWJC vgteS8AG+mGIJFF3uNjeuXuX/ExocERyJqQiPV+diDs5SkSU8Pur03uLzm48bT9nuvO3 omWVMBLojUXsqqa6pzAEUkRPxedGrC2FtL+cbCxCRFaJ9pZaL5TWaz7r7Xju71jMs1Pf uKrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QPjoY8ZbuoqomqizwrDxTKQEKSvTaRluAswzIwRCQRs=; b=sOtPZpXy2OpNt8rWyWFolnFApGCHFkfU+G6CtuBGwOL2+zHl5hYCybB3ms+Grj+72N 5EwQAx/wqrbnXommRAI0gc0hSQ1rYNDUYXEWJ29OJsfaBtErHIKA4F0g7kfkFOQiD1wT jUs0qFm3BiNNtG8tcOI7nW9FXn6OJS7fXHNcZHwqxdDKq03l38BQgU6JmWU3iW2dIBIJ qAtHgYMh3tqEbmzt8ZnyEJSP6ie5gQ4S3Cy6Q8UK+WSR6X9pU9fD+Sl0lJwz8em6k1Ms Z/dD3pA5G+3rq25uvLh9RpYMAwWv065CVhEJnSl5dP4nMKDlU9x/q0Ye6pPsvyoMtbGO JruA== X-Gm-Message-State: ANoB5plBf0UAl9VAAjYO7jfL4r80Axj5ETfsQN901uLN5wljCaYtsSYG JrK5QOpMBqjnNZ7sFE9tg9gwlywpTmA= X-Google-Smtp-Source: AA0mqf4KMvy1emWIY3f0ftEwqcnJKAjI5VsdVMnQLG/bnAzfEehzy9KMQR7hFHzeIyJFQxOHfcffqQ== X-Received: by 2002:a17:903:512:b0:185:441e:222c with SMTP id jn18-20020a170903051200b00185441e222cmr6429010plb.39.1670614689157; Fri, 09 Dec 2022 11:38:09 -0800 (PST) Received: from [10.128.57.14] ([155.98.131.6]) by smtp.gmail.com with ESMTPSA id v9-20020a1709029a0900b0017f36638010sm1660535plp.276.2022.12.09.11.38.08 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Dec 2022 11:38:08 -0800 (PST) Message-ID: <04759d61-3782-2787-5d66-3bc93bfc4230@gmail.com> Date: Fri, 9 Dec 2022 12:38:07 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: Change detection Content-Language: en-CA To: pgsql-sql@lists.postgresql.org References: From: Rob Sargent In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12/9/22 12:32, Shaozhong SHI wrote: > That works well. > > I just wonder whether we can tell Tom or Tim has worked in more than 1 > department.  Apparently, PostgreSQL does not allow count(distinct > department) when window function is used. > > Given this data set, can we do something like count(distinct) to > provide an answer to how many different department someone has worked in? > > Regards, > > David Use the working query in a CTE and simply do the count(distinct department) on that, else there's no good place to put the number of departments per person. Pretty sure you've been asked before but Please don't top post.