-
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
-
PHP Code:
SQL> select * 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_id) ct1,
3 (select count(*) from t1 where mo_id = a.lo_id) ct2
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
-
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 01:21 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|