Re: counting related rows

Поиск
Список
Период
Сортировка
От Frank Bax
Тема Re: counting related rows
Дата
Msg-id BLU0-SMTP965F0BF4A84C81E4C7400BAC500@phx.gbl
обсуждение исходный текст
Ответ на counting related rows  (James Cloos <cloos@jhcloos.com>)
Ответы Re: counting related rows  (James Cloos <cloos@jhcloos.com>)
Список pgsql-sql
James Cloos wrote:
> I have a table which includes a text column containing posix-style
> paths.  Ie, matching the regexp "^[^/]+(/[^/]+)*$".
> 
> I need to do a query of a number of columns from that table, plus the
> count of rows which are "children" of the current row.
> 
> The query:
> 
>   SELECT count(*) AS nch FROM m WHERE o = (SELECT o FROM m WHERE id=30016)
>                 AND name ILIKE (SELECT name || '/%' FROM m WHERE id=30016);
> 
> selects that extra column given the id.
> 
> A view containing all of the columns from m plus a column matching the
> above select would cover my needs well.
> 
> But I haven't been able to get the syntax right.


It would help if you provided:
a) statements to create sample data
b) expected results from sample data

Does this do what you want?

select * from m, (SELECT count(*) AS nch FROM m WHERE o = (SELECT o FROM 
m WHERE id=30016) AND name ILIKE (SELECT name || '/%' FROM m WHERE 
id=30016)) om;




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

Предыдущее
От: James Cloos
Дата:
Сообщение: counting related rows
Следующее
От: Rob Sargent
Дата:
Сообщение: Re: Duplicates Processing