X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id BADF6564A5 for ; Tue, 8 Mar 2005 04:34:16 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 33793-03 for ; Tue, 8 Mar 2005 04:34:15 +0000 (GMT) Received: from mxsf25.cluster1.charter.net (mxsf25.cluster1.charter.net [209.225.28.225]) by svr1.postgresql.org (Postfix) with ESMTP id 8935E5445B for ; Tue, 8 Mar 2005 04:34:14 +0000 (GMT) Received: from mxip06.cluster1.charter.net (mxip06a.cluster1.charter.net [209.225.28.136]) by mxsf25.cluster1.charter.net (8.12.11/8.12.11) with ESMTP id j284YCGq002450 for ; Mon, 7 Mar 2005 23:34:12 -0500 Received: from pc-68-118-180-13.will.ct.charter.com (HELO [192.168.116.102]) (68.118.180.13) by mxip06.cluster1.charter.net with ESMTP; 07 Mar 2005 23:34:12 -0500 X-Ironport-AV: i="3.90,145,1107752400"; d="scan'208"; a="650017693:sNHT13696652" Message-ID: <422D2BD8.2070806@NarrowPathInc.com> Date: Mon, 07 Mar 2005 23:36:40 -0500 From: Keith Worthington Reply-To: KeithW@NarrowPathInc.com Organization: Narrow Path, Inc. User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Cc: John McGough Subject: Re: SQL query help? References: <393ddoF5pqrfaU1@individual.net> In-Reply-To: <393ddoF5pqrfaU1@individual.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.139 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200503/121 X-Sequence-Number: 20600 John McGough wrote: >SELECT Count(*) FROM Work WHERE (UserID='user1' AND MAX(Finished)=0) > >Work:- >+---+-------+--------+---------+----------+ > | ID | JobID | UserID | Finished | Comment | >+---+-------+--------+---------+----------+ > | 1 | 1 | user1 | 0 | ... | > | 2 | 1 | user1 | 1 | ... | > | 3 | 2 | user2 | 0 | ... | > | 4 | 3 | user1 | 0 | ... | > | 5 | 2 | user2 | 0 | ... | > | 6 | 2 | user1 | 1 | ... | > | 7 | 3 | user1 | 0 | ... | >+---+-------+--------+---------+----------+ > >All I want it to do is return the number of unfinished jobs for a specific >user. > >In this example it would return 1 because job number 3 is not finished and >user1 was the last person working on it. > >but I keep getting MySQL error #1111 - Invalid use of group function > > John, I may be missing something but how about SELECT count(id) AS unfinished FROM work WHERE userid = 'user1' AND finished = 0 GROUP BY jobid; -- Kind Regards, Keith