RE: Get COUNT results from two different columns

2021-09-24 Thread Clive Swan
m: David G. Johnston [mailto:david.g.johns...@gmail.com] Sent: 23 September 2021 17:45 To: clives...@gmail.com Cc: pgsql-generallists.postgresql.org Subject: Re: Get COUNT results from two different columns On Thu, Sep 23, 2021 at 6:37 AM Clive Swan wrote: Greetings, I have two separate queries th

Re: Get COUNT results from two different columns

2021-09-23 Thread David G. Johnston
On Thu, Sep 23, 2021 at 6:37 AM Clive Swan wrote: > Greetings, > > I have two separate queries that work individually, returning a count from > each column. > > > > I want to subtract New(COUNT) from Old(Count) > > > I get an error when trying to run UNION? > While you finally did provide this

RE: Get COUNT results from two different columns

2021-09-23 Thread Clive Swan
] Sent: 23 September 2021 14:50 To: clives...@gmail.com Cc: pgsql-general@lists.postgresql.org Subject: RE: Get COUNT results from two different columns Hi, > I have two separate queries that work individually, returning a count from > each column. > I would appreciate any

Re: Get COUNT results from two different columns

2021-09-23 Thread Marc Olivé
Seems to me that's not an UNION, but a JOIN: SELECT o.old_count - n.new_count, o.old_sup, n.new_sup FROM ( SELECT new_sup, COUNT(new_sup) FROM public."Data" GROUP BY new_sup ) n JOIN ( SELECT old_sup, COUNT(old_sup) FROM public."Data" GROUP BY old_sup ) o ON o.old_su

RE: Get COUNT results from two different columns

2021-09-23 Thread SQL Padawan
Hi, > I have two separate queries that work individually, returning a count from > each column. > I would appreciate any pointers. > new_sup,  COUNT(new_sup) AS new_sup_count >     old_sup,  COUNT(old_sup) AS old_sup_count At least some of your problem is here - in your UNION-ed table,

Re: Get COUNT results from two different columns

2021-09-23 Thread Ray O'Donnell
On 23/09/2021 14:37, Clive Swan wrote: Greetings, I have two separate queries that work individually, returning a count from each column. I want to subtract New(COUNT) from Old(Count) I get an error when trying to run UNION? At a quick guess, you'll need to move the subtraction outside the

RE: Get COUNT results from two different columns

2021-09-23 Thread Clive Swan
Greetings, I have two separate queries that work individually, returning a count from each column. I want to subtract New(COUNT) from Old(Count) I get an error when trying to run UNION? I would appreciate any pointers. -- COUNT NEW SUPPLIER -- SELECT new_sup, COUNT(new_sup) FRO