[GENERAL] division by zero issue

2004-09-15 Thread Greg Donald
Converting some MySQL code to work with Postgres here. I have this query: SELECT tasks.task_id, (tasks.task_duration * tasks.task_duration_type / count(user_tasks.task_id)) as hours_allocated FROM tasks LEFT JOIN user_tasks ON tasks.task_id = user_tasks.task_id WHERE tasks.task_milestone =

Re: [GENERAL] division by zero issue

2004-09-15 Thread Jean-Luc Lachance
Add : AND count(user_tasks.task_id) 0 in the where clause. Greg Donald wrote: Converting some MySQL code to work with Postgres here. I have this query: SELECT tasks.task_id, (tasks.task_duration * tasks.task_duration_type / count(user_tasks.task_id)) as hours_allocated FROM tasks LEFT JOIN

Re: [GENERAL] division by zero issue

2004-09-15 Thread Guy Fraser
Maybe try something like this : SELECT task_id, CASE WHEN task_count = '0' THEN '0'::int4 ELSE (task_duration * task_duration_type / task_count) as hours_allocated END FROM (SELECT task_id, task_duration, task_duration_type, count(user_tasks.task_id) as task_count

Re: [GENERAL] division by zero issue

2004-09-15 Thread Greg Donald
On Wed, 15 Sep 2004 12:55:24 -0400, Jean-Luc Lachance [EMAIL PROTECTED] wrote: Add : AND count(user_tasks.task_id) 0 in the where clause. I get the error: aggregates not allowed in WHERE clause -- Greg Donald http://gdconsultants.com/ http://destiney.com/ ---(end

Re: [GENERAL] division by zero issue

2004-09-15 Thread Peter Eisentraut
Greg Donald wrote: I get the error: aggregates not allowed in WHERE clause Try HAVING then. -- Peter Eisentraut http://developer.postgresql.org/~petere/ ---(end of broadcast)--- TIP 5: Have you checked our extensive FAQ?

Re: [GENERAL] division by zero issue

2004-09-15 Thread David Fetter
On Wed, Sep 15, 2004 at 12:23:55PM -0500, Greg Donald wrote: On Wed, 15 Sep 2004 12:55:24 -0400, Jean-Luc Lachance [EMAIL PROTECTED] wrote: Add : AND count(user_tasks.task_id) 0 in the where clause. I get the error: aggregates not allowed in WHERE clause HAVING

Re: [GENERAL] division by zero issue

2004-09-15 Thread Tom Lane
Greg Donald [EMAIL PROTECTED] writes: On Wed, 15 Sep 2004 12:55:24 -0400, Jean-Luc Lachance [EMAIL PROTECTED] wrote: Add : AND count(user_tasks.task_id) 0 in the where clause. I get the error: aggregates not allowed in WHERE clause You need to put it in HAVING, instead. Note also this