nextval per counted
От | Rob Sargent |
---|---|
Тема | nextval per counted |
Дата | |
Msg-id | 71aa4ae1-f789-485a-ae58-2acec9aa2df0@gmail.com обсуждение исходный текст |
Ответы |
Re: nextval per counted
|
Список | pgsql-general |
I'm trying to craft SQL to invoke a sequence nextval once per grouped value.
So far I have this:
The following lets me count the "fixes" as a mate
Any pointers appreciated.
So far I have this:
with husb as(which works nicely but it "ids" each null separately.
select e.ma, count(distinct coalesce(e.pa, nextval('egogen')::text)) as mates
from emp_all_by3 e group by e.ma order by mates
)
select mates, count(*)
from husb
group by mates order by mates desc;
The following lets me count the "fixes" as a mate
with husb as(but I would love to able to assign a single "nextval" to those fixes.
select e.ma, count(distinct coalesce(e.pa, nextval('egogen')::text)) mates
from emp_all_by3 e
where ma is not null
group by e.ma order by mates
)
select mates, count(*) from husb group by mates order by mates desc;
with husb as(
select e.ma, coalesce(e.pa,'fix') as pa
from emp_all_by3 e
where e.ma is not null
),
fixed as (
select e.ma, count(distinct e.pa) mates
from husb e group by e.ma order by mates
)
select mates, count(*) from fixed group by mates order by mates desc;
Any pointers appreciated.
В списке pgsql-general по дате отправления: