Analytical qry help
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: Analytical qry help

  1. #1
    Join Date
    Jul 2000
    Location
    brewster,Newyork
    Posts
    87

    Analytical qry help

    I have a table t1(lo_id,so_id,mo_id,timemove,..,.,.)
    lo_id so_id mo_id time,,,,
    412A 412B 412A
    412B 412A 412A
    412C 412C 412D
    412D 412D 412D

    NOW HERE I WANT TO FIND OUT FOR EVERY LO_ID HOW MANY SO_ID'S AND MO_ID'S. IN THE ABOVE CASE IT IS FOR 412A THERE IS 1 SO-ID AND 2 MO_ID.Guys (Slimdave) please help me out in writing the qry
    THIS IS LIKE MANY TO MANY RELATIONSHIP.LO_ID IS THE PRIMARY KEY.
    sat

  2. #2
    Join Date
    May 2000
    Location
    ATLANTA, GA, USA
    Posts
    3,136
    PHP Code:
    SQLselect from t1 ;

    LO_ID      SO_ID      MO_ID
    ---------- ---------- ----------
    412A       412B       412A
    412B       412A       412A
    412C       412C       412D
    412D       412D       412D

      1  select lo_id
    ,
      
    2         (select count(*) from t1 where so_id a.lo_idct1,
      
    3         (select count(*) from t1 where mo_id a.lo_idct2
      4
    from   t1 a
    SQL
    > /

    LO_ID             CT1        CT2
    ---------- ---------- ----------
    412A                1          2
    412B                1          0
    412C                1          0
    412D                1          2

    SQL
    spool off

    Is this you are looking for?

    If the answer is correct, I will try to write ANALYTIC QUERY.

    Tamil

  3. #3
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    No analytic function required ...

    Code:
    Select lo_id,
           count(Distinct so_id) so_id#,
           count(distinct mo_id) mo_id#
    From   t1
    group by
           lo_id
    Edit: Oh, no I misunderstood the question.
    Tamil's sol'n looks like the right approach
    Last edited by slimdave; 03-01-2005 at 12:21 PM.
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width