| From: | "Gordan Bobic" <gordan(at)freeuk(dot)com> |
|---|---|
| To: | <pgsql-general(at)postgresql(dot)org> |
| Subject: | Built in Functions use with recordsets |
| Date: | 2000-11-30 10:58:33 |
| Message-ID: | 00c701c05abc$7e8e9980$8000000a@localdomain |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Hi.
I'm trying to get an average value (avg()) of a certain attribute in a
table. The snag is, I don't want this across a whole table. I only want it
over a certain set of records. In effect, I want to do something like:
SELECT somefield
FROM sometable
WHERE otherfield = 'criteria'
ORDER BY thirdfield
LIMIT 10
and then do an avg(somefield).
Can this be done without using temp tables, in a single query? I tried
making a function that does this, but even if I used temp tables, the
function didn't work, claiming that the table didn't exist.
Ideally, I want to do something like:
SELECT avg
(
SELECT somefield
FROM sometable
WHERE otherfield = 'criteria'
ORDER BY thirdfield
LIMIT 10
) as somefieldname
But the parser doesn't seem to like it.
How can I do this?
Thanks.
Gordan
| From | Date | Subject | |
|---|---|---|---|
| Next Message | JB | 2000-11-30 11:41:50 | Re: [PHP] RE: [SQL] a script that queries database periodically |
| Previous Message | Peter Maas | 2000-11-30 10:56:19 | Re: function to return query result |