SQL If-Then Logic in Query - Mailing list pgsql-general

From User
Subject SQL If-Then Logic in Query
Date
Msg-id D3jZ8.568593$cQ3.53253@sccrnsc01
Whole thread Raw
Responses Re: SQL If-Then Logic in Query
Re: SQL If-Then Logic in Query
List pgsql-general
Hi everyone,

I've been racking my brain against this problem for a few days now and
figured I'd turn it over to the experts.  I have a table with three columns.
Lets call them:

User ID            Text
Department       Numeric
Percent             Numeric

* No primary key - sorry

A User's time is broken up amongst different departments
I need to show a single record for each user id with the department they
belong to that has the greatest percentage.  I've been able to do this with
the max(percent) and group by approach.  However, I run into issues when the
breakdown between two departments is an exact 50%.  So, to make a long story
short, I need to translate the following logic into SQL:

Display results with the columns User ID, Department, Percent but only show
the department with the highest percentage for each user id and if the
percentage is 50% between two departments, show the department with the
highest numberic value as a differentiating factor.

If this is not the correct group to post this question, sorry in advance.
If you can point me to a web site that may have a tutorial with an example
similar to this, I'd appreciate it...

Thanks!





pgsql-general by date:

Previous
From: trev@trev.co.nz (Trev)
Date:
Subject: ERROR: bt_fixroot: not valid old root page
Next
From: brendanl@iname.com (Brendan LeFebvre)
Date:
Subject: Stubborn lock(?) with psqlODBC+MSAccess