Store classic problem

xiaoxiao2021-03-06  41

Just involve a table: xkb_treenode table structure is this: node_id int // node IDParentNode_ID INT // Parent Node IDNode_text varchar // Node Content IsModule Bit // Whether Leaf Node Saved Saved Data: Node_ID ParentNode_ID Node_Text IsModule 1 -1 Language And literature 0 2 -1 mathematics 0 3 -1 technology 0 4 1 language 0 5 1 Foreign language 0 6 5 English 0 7 6 Junior English 0 8 7 Tita 1 9 4 Determination is 2 1 10 2 Test 3 1 The problem is : Can you make a stored procedure, according to the value of the IsModule field in the table (the final leaf node of the value of 1), such as "Tes" is the leaves node, and the layer is in progress into "Tes" Ancestral Node: Tower -> Junior English -> English -> Foreign Language -> Language and Literature That is to find "Language and Literature" to finally return the form: Leaf Node ID Parent Node ID Name Name Ancestral Node Name Ancestral Node ID 8 7 Testa Language and Literature 1 9 4 Determination is 2 Language and Literature 1 10 2 Test 3 Mathematics 2 / Correct Answer: - generating test data create table xkb_treeNode (node_id int, parentNode_id int, node_textvarchar (10), isModulebit) insert into xkb_treeNode select 1, -1, 'language and literature', 0insert into xkb_treeNode select 2, -1, 'mathematics,' 0INSERT INTO XKB_TREENODE SELECT 3, -1, 'Technology', 0insert Into XKB_TREENODE SELECT 4, 1, 'Language', 0insert Into XKB_Treenode SELECT 5, 1, 'Foreign Language', 0insert Into XKB_Treenode SELECT 6, 5, 'English', 0insert INTO XKB_TREENODE SELECT 7, 6, 'Junior English', 0insert Into XKB_TREENODE SELECT 8, 7, 'Test', 1Isert Into XKB_TREENODE SELECT 9, 4, 'Determination is 2', 1insert Into Xkb_treenode SELECT 10, 2, 'Test 3 '

转载请注明原文地址:https://www.9cbs.com/read-53705.html

New Post(0)