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

Поиск
Список
Период
Сортировка
От Moreno Andreo
Тема Re: SQL problem (forgot to change header with earlier post!).
Дата
Msg-id 8f12a928-d79c-f9f8-197e-4750e203b643@evolu-s.it
обсуждение исходный текст
Ответ на SQL problem (forgot to change header with earlier post!).  (Paul Linehan <linehanp@tcd.ie>)
Ответы Re: SQL problem (forgot to change header with earlier post!).  (Paul Linehan <linehanp@tcd.ie>)
Список 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 по дате отправления:

Предыдущее
От: Andreas Kretschmer
Дата:
Сообщение: Re: binaries for 11 beta compiled with --with-llvm?
Следующее
От: Paul Linehan
Дата:
Сообщение: Re: SQL problem (forgot to change header with earlier post!).