Home » SQL & PL/SQL » SQL & PL/SQL » sql problem (Oracle
sql problem [message #366339] Fri, 12 December 2008 19:20 Go to next message
Messages: 61
Registered: November 2008

I am getting data from a query returning data for Gender 'MALE' like below:

Gender Population Occupation Location

MALE 56 Cultivator Alaska
MALE 44 Service NY
MALE 97 Doctor NY

Now from this query I need to write a query that returns
recodrs based on two criteria

1. Return rows that is 0-30% of total population for male

ie retrive rows that is ( population <= .5 * total sum of (male)population)
2 0-100% and so on..
Re: sql problem [message #366347 is a reply to message #366339] Fri, 12 December 2008 22:30 Go to previous messageGo to next message
Messages: 941
Registered: December 2008
Location: Surat, The Diamond City
Senior Member
So simple,

Put the query(of which you shown output) into inner query.
Then you can put aggrigate function in WHERE clause in outer query.

Re: sql problem [message #366363 is a reply to message #366339] Sat, 13 December 2008 01:20 Go to previous message
Michel Cadot
Messages: 65088
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Already said to you:
Please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code (See SQL Formatter) and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version (4 decimals).

Post a test case: create table and insert statements along with the result you want with these data.

Use SQL*Plus and post what you tried so far.

Previous Topic: How send a mail dynamically
Next Topic: case work in 8.1.7 or not ? (Im getting an error)
Goto Forum:

Current Time: Wed Jul 26 18:09:43 CDT 2017

Total time taken to generate the page: 0.12657 seconds