Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Aggregate SQL Help
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