Re: sql issue

From: Daniel Morgan <dmorgan_at_exesolutions.com>
Date: Thu, 26 Sep 2002 22:10:40 GMT
Message-ID: <3D9385D2.7A99888B_at_exesolutions.com>


Karsten Farell wrote:

> Pretty tough in vanilla SQL. Can do something like this in PL/SQL:
>
> DECLARE
> cursor c_state is
> select state
> from a_table
> order by state;
> cursor c_county (vin_state in varchar2) is
> select county
> from a_table
> where state = vin_state
> order by county;
> knt number;
> BEGIN
> for r_state in c_state loop
> knt := 0;
> for r_county in c_county (r_state.state) loop
> knt := knt + 1;
> if knt <= 50 then
> dbms_output.put_line('State: '||r_state.state||
> ' County: '||r_county.county);
> end if;
> end loop;
> end loop;
> END;
>
> Of course, if this is a homework assignment and you *must* do it in SQL,
> then you'll have to work on correlated subqueries.
>
> yreddy wrote:
> > I have a table with state , county and many more columns, i want to
> > select 50 rows for every county in a state. This table has all the
> > states and multiple counties per state. I am not worried about
> > duplicate counties or anything. Just want the 50 records for every
> > county in all the states
> >
> > thanks

[Quoted] Please compare your response with those of Bricklen and Kevin. You didn't lend a helping hand ... you didn't give a few pointers ... you handed the complete and total solution.

And had it been one of my students I would be less than pleased with both of you.

Please rethink what you did ... because I can assure you that no one learns to eat by being spoon fed.

Daniel Morgan
http://www.extension.washington.edu/extinfo/certprog/oad/oad_crs.asp Received on Fri Sep 27 2002 - 00:10:40 CEST

Original text of this message