Dave,
Try:
select distinct on (sessionid) sum(sessiontime) from logs
where name='joeblowuser' and datetime > 1036040400
group by sessionid.
sum() is an aggerate (sp?) function, that means it munges a field
(sessiontime) from multiple records into one field in one record. Since you
are also selecting sessionid (from mulitple records) you need to munge it
some how, that munge is accomplished via 'group by'. From your previous
e-mail it seems that (IMHO) the real problem is that duplicates are getting
inserted via external hardware interaction, this select might be a bandage
on a wound whose true size isn't known...
PostgreSQL docs:
Distinct:
http://www.postgresql.org/idocs/index.php?queries-select-lists.html
Group By:
http://www.postgresql.org/idocs/index.php?sql-select.html
/B
----- Original Message -----
From: "Dave" <dave@hawk-systems.com>
To: <pgsql-php@postgresql.org>
Sent: Thursday, November 21, 2002 10:43
Subject: Re: [PHP] Selecting distinct records
> >What I am looking to do is
> >- grab every record for $user
> >- remove any records that have identical ipaddress+sessionid+refid
> >- then sort the results by date_time or something else
>
> this last requirement is where the problem is...
>
> is you do a sum() or order by in the select statement you get and error,
for
> example;
>
> select distinct on (sessionid) sum(sessiontime) from logs where
> name='joeblowuser' and datetime > 1036040400;
>
> ERROR: Attribute logs.sessionid must be GROUPed or used in an aggregate
> function
>
> Same if you have to order by datetime or something...
>
> Dave
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org