Re: SQL problem (forgot to change header with earlier post!). - Mailing list pgsql-general

From Moreno Andreo
Subject Re: SQL problem (forgot to change header with earlier post!).
Date
Msg-id 8f12a928-d79c-f9f8-197e-4750e203b643@evolu-s.it
Whole thread Raw
In response to SQL problem (forgot to change header with earlier post!).  (Paul Linehan <linehanp@tcd.ie>)
Responses Re: SQL problem (forgot to change header with earlier post!).  (Paul Linehan <linehanp@tcd.ie>)
List pgsql-general
Il 29/05/2018 13:14, Paul Linehan ha scritto:
> Hi all,
>
> I have a problem that I just can't seem to solve:
>
> I want to divide the count of one table by the count of another -
> seems simple enough!
> I created simple VIEWs with counts of the tables, but I just can't
> grasp the logic!
If it's not an excercise, I think you don't need them
> DDL and DML (simplified) at the bottom of post.
>
>
> I tried various combinations of things like basic SELECTs.
>
>
> SELECT avg FROM ((SELECT cnt1 FROM v1)/(SELECT cnt2 FROM v2));

Maybe I didn't catch the problem, but

select (select count(*) from t1) / (select count(*) from t2)::float

should be a starting point (if you need an integer as a return value, 
simply remove the ::float at the end

HTH
Moreno.-



pgsql-general by date:

Previous
From: Andreas Kretschmer
Date:
Subject: Re: binaries for 11 beta compiled with --with-llvm?
Next
From: Paul Linehan
Date:
Subject: Re: SQL problem (forgot to change header with earlier post!).