| From: | "Oliver Elphick" <olly(at)lfix(dot)co(dot)uk> |
|---|---|
| To: | adamcrume(at)hotmail(dot)com (Adam) |
| Cc: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: count of occurrences |
| Date: | 2001-09-14 20:28:22 |
| Message-ID: | 200109142028.f8EKSMIn005682@linda.lfix.co.uk |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Adam wrote:
>I help run a job database and have a table of search records. I want
>a query that will return the top 10 jobs by search frequency. I'm
>familiar with ORDER BY and LIMIT, so I basically need this:
>
>Given a table search_records:
>job_num
>-------
>1
>2
>2
>3
>4
>4
>4
SELECT job_num, COUNT(*)
FROM search_records
GROUP BY job_num
ORDER BY COUNT(*) DESC
LIMIT 10;
--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47 6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"But without faith it is impossible to please him; for
he that cometh to God must believe that he is, and
that he is a rewarder of them that diligently seek
him." Hebrews 11:6
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Oliver Elphick | 2001-09-14 20:30:01 | Re: How to implement transaction in plpgsql? |
| Previous Message | Patrik Kudo | 2001-09-14 20:26:40 | Re: Case sensitivity issue |