Re: count of occurences

From: "Eric Ridge" <ebr(at)tcdi(dot)com>
To: "Adam" <adamcrume(at)hotmail(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: count of occurences
Date: 2001-09-14 20:33:28
Message-ID: D3ADE25911614840BC69C72E3171E4ED0FBB37@tcdiexch.tcdi.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Browse pgsql-general by date

  From Date Subject
Next Message Mark E. Pennell 2001-09-14 21:06:13 Transition from MS-SQL - Store Procedures?
Previous Message roypgsqlgen 2001-09-14 20:31:39 problems using COPY