Home > database > Optimize the code, I don't know how to write.
Optimize the code, I don't know how to write.
Time:09-18
Very grateful to the great god, I have a question, the following code to continue cycle bottom go to, don't know how to write, that I only write at level 5, but the reality may be level 20,,, thank god help me to solve the ah, thank you,
SELECT id, hhr_name, parent_id tjr_id FROM gbi_hhr WHERE id=90
OR Id IN ((SELECT id FROM gbi_hhr WHERE tjr_id=90 AND sf_type='strategy'))
OR Id IN (SELECT id FROM gbi_hhr WHERE sf_type!='strategic' AND tjr_id IN (SELECT id FROM gbi_hhr WHERE id IN ((SELECT id FROM gbi_hhr WHERE tjr_id=90 AND sf_type='strategy'))))
OR Id IN (SELECT id FROM gbi_hhr WHERE sf_type!='strategic' AND tjr_id IN (SELECT id FROM gbi_hhr WHERE sf_type!='strategic' AND tjr_id IN (SELECT id FROM gbi_hhr WHERE id IN ((SELECT id FROM gbi_hhr WHERE tjr_id=90 AND sf_type='strategy')))))
OR Id IN (SELECT id FROM gbi_hhr WHERE sf_type!='strategic' AND tjr_id IN (SELECT id FROM gbi_hhr WHERE sf_type!='strategic' AND tjr_id IN (SELECT id FROM gbi_hhr WHERE sf_type!='strategic' AND tjr_id IN (SELECT id FROM gbi_hhr WHERE id IN ((SELECT id FROM gbi_hhr WHERE tjr_id=90 AND sf_type='strategy'))))))
CodePudding user response:
Try using a recursive bai
CodePudding user response:
@ stelf thank you for your answer, how do you write a recursive, can you give me a sample code, thank you, just learn this, don't know much about,
CodePudding user response:
You have serious problem this code design, grade 5 is what concept, you work it out: suppose you have 100 records IN accordance with the 100 x100x100x100x100 time to execute, don't know what you're thinking is what, help you to simplify the second paragraph: id IN ((SELECT id FROM gbi_hhr WHERE tjr_id=90 AND sf_type='strategy')) which can be simplified as: tjr_id=90 AND sf_type='strategic' other of your own,