pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Keith Worthington <KeithW@NarrowPathInc.com>
To: pgsql-sql@postgresql.org
Cc: John McGough <goff@funkster.org.uk>
Subject: Re: SQL query help?
Date: Mon, 07 Mar 2005 23:36:40 -0500
Message-ID: <422D2BD8.2070806@NarrowPathInc.com> (raw)
In-Reply-To: <393ddoF5pqrfaU1@individual.net>
References: <393ddoF5pqrfaU1@individual.net>

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




view thread (6+ messages)  latest in thread

Message-ID: <422D2BD8.2070806@NarrowPathInc.com>
Permalink:  ../422D2BD8.2070806@NarrowPathInc.com/
Also on:    postgresql.org/message-id/422D2BD8.2070806@NarrowPathInc.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: KeithW@NarrowPathInc.com, goff@funkster.org.uk
  Subject: Re: SQL query help?
  In-Reply-To: <422D2BD8.2070806@NarrowPathInc.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox