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

Home -> Community -> Mailing Lists -> Oracle-L -> Re: sql query

Re: sql query

From: Jon Walthour <jonw_at_fuse.net>
Date: Wed, 22 Aug 2001 07:36:11 -0700
Message-ID: <F001.00373D82.20010822065132@fatcity.com>

Seema:

Here's my crack at it:

select x.userid

       , x.superid
       , nvl(y.count, 0) as count
    from mytable x
       , (select   a.userid
                 , a.superid
                 , count(*) as count
              from mytable a
                 , mytable b
             where a.userid=b.superid
          group by a.userid, a.superid) y
   where x.userid = y.userid(+)
order by 1, 2;

Jon Walthour
>
> From: "Seema Singh" <oracledbam_at_hotmail.com>
> Date: 2001/08/22 Wed AM 09:00:28 EDT
> To: Multiple recipients of list ORACLE-L <ORACLE-L_at_fatcity.com>
> Subject: sql query
>
> Hi
> One table has following information
> userid superid
> 14 -1
> 4 0
> 8 2
> 9 2
> 15 2
> 24 4
> 16 4
> 25 4
> 6 5
> 7 5
> 26 5
> 2 16
> 18 16
> 10 18
> 11 18
> 1 24
> 5 24
> 13 24
> I want the output in following format
> userid superid COUNT
> 14 -1 0
> 4 0 3
> 8 2 0
> 9 2 0
> 15 2 0
> 24 4 3
> 16 4 2
> 25 4 0
> 6 5 0
> 7 5 0
> 26 5 0
> 2 16 3
> 18 16 2
> 10 18 0
> 11 18 0
> 1 24 0
> 5 24 3
> 13 24 0
> Where userid =xx , select count where Superid=xx
> Please suggest the query.
> THANKS
> -Seema
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
>
> --
> Please see the official ORACLE-L FAQ: http://www.orafaq.com
> --
> Author: Seema Singh
> INET: oracledbam_at_hotmail.com
>
> Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051
> San Diego, California -- Public Internet access / Mailing Lists
> --------------------------------------------------------------------
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB ORACLE-L
> (or the name of mailing list you want to be removed from). You may
> also send the HELP command for other information (like subscribing).
>

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Jon Walthour
  INET: jonw_at_fuse.net

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Wed Aug 22 2001 - 09:36:11 CDT

Original text of this message

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