Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Aggregate SQL Help

Aggregate SQL Help

From: tacnaboyz <tacnaboyz_at_yahoo.com>
Date: 6 Aug 2002 12:22:11 -0700
Message-ID: <14d3214a.0208061122.f03456b@posting.google.com>


Hello everyone,
I'm thinking this must be relatively simple, but my brain is not cooperating. Let's say I had a table like this...

FirstName | LastName | Sex | State
----------|----------|-----|------
Jim       | Beam     | M   | AK
Buddy     | Hackett  | M   | AK
Janet     | Reno     | F   | AK
Sexy      | Sally    | F   | NY

For each state, I want to know if there are more males or more females.... and for my query, the only column I can have in my "GROUP BY" clause is "STATE". So I need something along these lines (though obviously incorrect)....

SELECT STATE, MAX(SEX) AS MAJORITY_SEX FROM MY_TABLE GROUP BY STATE I would like to see a query result of...

STATE | MAJORITY_SEX
------|-------------
AK    | M
NY    | F

I'm thinking I can somehow do this with some of Oracle's aggregate functions, but I'm not seeing it.

Any ideas?

Thanks!!! Received on Tue Aug 06 2002 - 14:22:11 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US