Re: sql issue

From: Karsten Farell <kfarrell_at_medimpact.com>
Date: Thu, 26 Sep 2002 00:18:59 GMT
Message-ID: <Tnsk9.1710$Ol3.64215231_at_newssvr21.news.prodigy.com>


[Quoted] 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
Received on Thu Sep 26 2002 - 02:18:59 CEST

Original text of this message