| От | Tom Lane |
|---|---|
| Тема | Re: Calculating Percentages |
| Дата | |
| Msg-id | 24226.1052925819@sss.pgh.pa.us обсуждение |
| Ответ на | Calculating Percentages (David Siegal <dsiegal@brave.cs.uml.edu>) |
| Список | pgsql-sql |
David Siegal <dsiegal@brave.cs.uml.edu> writes:
> If I were to do:
> SELECT nationality, ((COUNT(*) * 100)/(select count(*) from member)) as
> percentage FROM member GROUP BY nationality ORDER BY nationality;
> would this repeatedly execute the inner query over and over?
No, it'd do it just once, because the sub-select has no dependency on
the outer select. (If the sub-select used any variables from the outer
level, then it'd have to be done over at each outer row.)
You can tell the difference between these cases by looking at EXPLAIN
output for the query: do-once sub-selects are labeled InitPlans,
do-every-time sub-selects are labeled SubPlans.
regards, tom lane
В списке pgsql-sql по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера