| От | Tom Lane |
|---|---|
| Тема | Re: Applying SUM twice in the same query. |
| Дата | |
| Msg-id | 2036.963676782@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | Applying SUM twice in the same query. (Rodger Donaldson <rodgerd@diaspora.gen.nz>) |
| Список | pgsql-sql |
Rodger Donaldson <rodgerd@diaspora.gen.nz> writes:
> What I really want to do with total is to derive a
> proportion of number of server:number of servers, something like:
Only way to do that is with a sub-select, because all the aggregates
appearing in a single query are going to be computed over the same
input set(s). Try
selectserver_name,sum(number) AS number,(select sum(number) from web_servers) AS total
from web_servers
group by server_name;
While this looks like it might be inefficient, it's really not because
Postgres recognizes that the inner select is independent of the outer
and only evaluates it once.
Note you need PG 7.0 or later to do this.
regards, tom lane
В списке pgsql-sql по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера