Re: Inline count on a query
От | David G. Johnston |
---|---|
Тема | Re: Inline count on a query |
Дата | |
Msg-id | CAKFQuwbHU9Bc8UcN8P7xGExVr7DoC8VqYxHAUyjuw_o6G7T_Zw@mail.gmail.com обсуждение исходный текст |
Ответ на | Inline count on a query (Laura Smith <n5d9xq3ti233xiyif2vp@protonmail.ch>) |
Ответы |
Re: Inline count on a query
|
Список | pgsql-general |
On Wednesday, August 19, 2020, Laura Smith <n5d9xq3ti233xiyif2vp@protonmail.ch> wrote:
Hi,
Let's say we've got a fairly basic table :
create table networks (
lan_id text not null,
net_id text not null,
port_id text not null
);
create index net_uniq on networks(lan_id,port_id);
The query conundrum I am facing is that I need to add metadata to the output of the query that indicates the count of ports a given net has on a lan.
So, for example, given :
insert into networks(lan_id,net_id,port_id) values('L1','N1,'P1');
insert into networks(lan_id,net_id,port_id) values('L1','N1,'P2');
The metadata count would be 1, 2 (because 'N1' has 'P1' and 'P2' on 'L1').
Is there a sensible way to query this without stressing out Postgres too much ? I'm guessing a CTE of some sort ?
Suggest you provide your desired output in table format, and show “the query” that you mention.
David J.
В списке pgsql-general по дате отправления: