MySQL Forums
Forum List  »  Newbie

Please help
Posted by: Praveen Pandit
Date: July 10, 2015 12:52PM

Hi,

I have requirement to create an output which should show the result in a hierarchical tree structure.

Below is the requirement.

I have table called dealers in which there are multiple columns, out of which I need to use the below columns to generate a hierarchical tree for generating a sales report for every month.

dealer_id
url
dlr_type
fk_parent_dealerid


1. "dlr_type" can contain the types like "GROUP", "DEALER".
2. For the Main Group there can be any number of sub-groups with the same dlr_type "GROUP"

3. For the dlr_type "GROUP" the fk_parent_dealerid is always NULL for the top most "GROUP" (for the main Group) in the hierarchy.

Example:

dealerid, url, dlr_type, fk_parent_dealerid
----------- ------------- -------------- ---------------------
102863, TGA, GROUP, (null)



4. For the next level, in the Main Group dealerid 102863 will be the fk_parent_dealerid

Example:

select dealerid, websiteurl, dealer_type, fk_parent_dealerid from dealers where dealerid = 102863;

The above query can give result like

dealerid, url, dlr_type, fk_parent_dealerid
----------- ------------------- -------------- ---------------------
102864, DITROEN SAVEL OUEST, GROUP, 102863
102876, DITROEN SAVEL EST, GROUP, 102863


Which are sub-groups for the main Group "TGA".

Similarly, if I use the dealerid 102864 from the above result it can display the next level hierarchy which can be a sub-group itself or a "DEALER".

When the dlr_type is "DEALER" that means that is the final node in the hierarchy which can have any number of elements starting from 1 to any number.

Example output with the final node elements with thr dlr_type = 'DEALER':

dealerid, url, dlr_type, fk_parent_dealerid
----------- ---------------------------- -------------- ---------------------
102866, dev.test.fr, DEALER, 102865
102867, dev.test1.fr, DEALER, 102865


Can anyone help in writing a SQL or stored procedure to generate the output?


Thanks & regards
P.Pandit

Options: ReplyQuote


Subject
Written By
Posted
Please help
July 10, 2015 12:52PM
July 10, 2015 12:58PM
July 10, 2015 09:01PM
July 11, 2015 03:30AM
July 11, 2015 04:00AM
July 11, 2015 08:37AM
July 11, 2015 11:24AM
July 11, 2015 01:10PM
July 11, 2015 01:24PM
July 12, 2015 12:28PM
July 12, 2015 12:46PM
July 12, 2015 04:08PM
July 13, 2015 02:10AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.