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

Поиск
Список
Период
Сортировка
От Paul Linehan
Тема Re: SQL problem (forgot to change header with earlier post!).
Дата
Msg-id CAF4RT5QAQxH+WvF+c7PRfM4AK=TbDwD9Egvi3Z58-LXXrNFu9g@mail.gmail.com
обсуждение исходный текст
Ответ на SQL problem (forgot to change header with earlier post!).  (Paul Linehan <linehanp@tcd.ie>)
Ответы Re: SQL problem (forgot to change header with earlier post!).  (Adrian Klaver <adrian.klaver@aklaver.com>)
Список pgsql-general
Hi again, and thanks for your efforts on my behalf!

> WITH num AS
> (
>    SELECT count (*) as cnt1 FROM v1
>  ),
> div AS
> (
>    SELECT count (*) as cnt2 FROM v2
>  )
>  SELECT (num.cnt1::numeric/div.cnt2)
> From num cross join div;


I've tried running this code 4 different ways and none of them work -
your original and my efforts to tweak the code!

This always ends up giving just 1 (integer division - using float) or
1.0000000000 (using numeric).

Check out the fiddle here:
https://dbfiddle.uk/?rdbms=postgres_10&fiddle=b1bd443baf16d85dee0436333a6fd919


> You could have also written it like your first statement without the CTEs.
> This way requires joining the tables with a cross or Cartesian join.

Yes, the first statement is the way to go on this particular case, but
I'm also trying to understand the ins and outs of CTEs, so I'm
interesting in solving this one!


Thanks again,


Rgs,


Pól...



> Todd


В списке pgsql-general по дате отправления:

Предыдущее
От: Paul Linehan
Дата:
Сообщение: Re: SQL problem (forgot to change header with earlier post!).
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: SQL problem (forgot to change header with earlier post!).