Re: SQL problem (forgot to change header with earlier post!).

From: Moreno Andreo <moreno(dot)andreo(at)evolu-s(dot)it>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: SQL problem (forgot to change header with earlier post!).
Date: 2018-05-29 11:39:53
Message-ID: 8f12a928-d79c-f9f8-197e-4750e203b643@evolu-s.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.-

In response to

Responses

Browse pgsql-general by date

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