I m working on table called FUT_USR_DETAILS
this table have columns child_id,Parent_id,Org_id
these columns have parent child relationship. org id is super parent.
suppose org id 1 is grand parent, parentid 1 is parent(for first time org id will be parent_id also as it creates parent id) and child id is child1
if child id1 creates user it becomes parent and it's entry goes in parentid column but for this entry it's org id column will have same value as in case when child id1 was child.
for all children, grandchildren,grand_grandchildren,so on, the org id will have same value.
i want to write a query to get level of count of hierarchy of particular user.
that is starting from grandparent(org id) how many generation levels are present for that org id .
i wrote a query to find this count. but i need to explicitly specify each rg id in query. this query does not work for entire table at time. query is
SELECT count(*)
FROM EXTDBA.fut_user_details
WHERE UD_ORG_ID ='F00761' //here i m specifying org id explicitly
AND UD_child_ID IN
(SELECT UD_PARENTID FROM EXTDBA.fut_user_details WHERE UD_ORG_ID ='F00761'
)
AND UD_child_ID!=UD_ORG_ID;
programmatically if i want to do this i'll do it like this.
select distinct org id from table. take it in array
anf for each item in array ie for each org id i'll run for llop
like
for(i=0;i<arrorgid.count;i++)>
{
SELECT count(*)
FROM EXTDBA.fut_user_details
WHERE UD_ORG_ID =arrOrgId[i] //here i m specifying org id explicitly
AND UD_child_ID IN
(SELECT UD_PARENTID FROM EXTDBA.fut_user_details WHERE UD_ORG_ID =arrOrgId[i]
)
AND UD_child_ID!=UD_ORG_ID;
}
but i m asked to do it by quering database directly.
can someone tell me how to do so