Re: count of occurences - Mailing list pgsql-general

From Eric Ridge
Subject Re: count of occurences
Date
Msg-id D3ADE25911614840BC69C72E3171E4ED0FBB37@tcdiexch.tcdi.com
Whole thread Raw
In response to count of occurences  (adamcrume@hotmail.com (Adam))
List pgsql-general
> I tried
>
> select distinct job_num, (select count(*) from search_records j where
> j.job_num=k.job_num) from search_records k

can't you just do:

select job_num, count(job_num) from search_records group by job_num
order by job_num

http://www.postgresql.org/idocs/index.php?queries.html#QUERIES-GROUP

and creating an index on job_num might improve performace even more, but
I don't know if index scans are used in aggregate functions or not.

eric

pgsql-general by date:

Previous
From: Philip Hallstrom
Date:
Subject: Re: get certain # of recs
Next
From: Linh Luong
Date:
Subject: Diabling constraints