Home > database >  MySQL to find father node
MySQL to find father node

Time:09-30

Have a MySQL database tables, hierarchy by parentId, format the following
Front end result:
I need to consult the node according to the parentId father-child node, for example a;
SQL statements:
 10.13 Distrib - MySQL dump 5.7.17, for Win64 (x86_64) 
-
Host: 192.168.22.103 Database: the hub
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
- Server version 5.7.21

/*! 40101 SET @ OLD_CHARACTER_SET_CLIENT=@ @ CHARACTER_SET_CLIENT */.
/*! 40101 SET @ OLD_CHARACTER_SET_RESULTS=@ @ CHARACTER_SET_RESULTS */.
/*! 40101 SET @ OLD_COLLATION_CONNECTION=@ @ COLLATION_CONNECTION */.
/*! 40101 SET NAMES utf8 */.
/*! 40103 SET @ OLD_TIME_ZONE=@ @ TIME_ZONE */.
/*! 40103 SET TIME_ZONE='+ 00:00 */.
/*! 40014 SET @ OLD_UNIQUE_CHECKS=@ @ UNIQUE_CHECKS, UNIQUE_CHECKS=0 */.
/*! 40014 SET @ OLD_FOREIGN_KEY_CHECKS=@ @ FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */.
/*! 40101 SET @ OLD_SQL_MODE=@ @ SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */.
/*! 40111 SET @ OLD_SQL_NOTES=@ @ SQL_NOTES, SQL_NOTES=0 */.

-
- Table structure for Table ` hub_sys_menu `
-

DROP TABLE IF the EXISTS ` hub_sys_menu `;
/*! 40101 SET @ saved_cs_client=@ @ character_set_client */.
/*! 40101 SET character_set_client=utf8 */;
The CREATE TABLE ` hub_sys_menu ` (
` menuid ` varchar (40) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'menu ids,
` menuname ` varchar (40) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'menu name,
` parentid ` varchar (40) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'parent menu ids,
` url ` varchar (500) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'page url,
` status ` varchar (1) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'status identification,
` icon ` varchar (500) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'icon',
` displayname ` varchar (40) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'display name'
` orderid ` int (11) the DEFAULT NULL COMMENT 'sort field,
PRIMARY KEY (` menuid `)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*! 40101 SET character_set_client=@ saved_cs_client */.

-
- Dumping the data for the table ` hub_sys_menu `
-

The LOCK TABLES ` hub_sys_menu ` WRITE;
/*! 40000 the ALTER TABLE ` hub_sys_menu ` DISABLE KEYS */.
INSERT INTO `hub_sys_menu` VALUES ('00ecdb96-e040-4bda-83f7-c70103b34876','表到表','31802045-aa0a-4c4c-a3b7-af5f0c5c276b',NULL,'1',NULL,'表到表',1),('03e143d1-e667-4a1f-bd3d-618ab072a35b','文件到表','31802045-aa0a-4c4c-a3b7-af5f0c5c276b',NULL,'1',NULL,'文件到表',2),('31802045-aa0a-4c4c-a3b7-af5f0c5c276b','作业设计',NULL,NULL,'1',NULL,'作业设计',1),('362284fb-e122-4260-9e71-934b28e78a62','矫正1','00ecdb96-e040-4bda-83f7-c70103b34876',NULL,'1',NULL,'矫正1',1),('3c19cf0e-78a1-4f6f-98c1-905af36089e0','矫正2','00ecdb96-e040-4bda-83f7-c70103b34876',NULL,'1',NULL,'矫正2',2),('3f9f661a-7a7f-48e3-83cf-a0e640726237','矫正3','00ecdb96-e040-4bda-83f7-c70103b34876',NULL,'1',NULL,'矫正3',3),('43bd85c5-78d1-442a-8bc7-f17d9fbe7111','矫正4','00ecdb96-e040-4bda-83f7-c70103b34876',NULL,'1',NULL,'矫正4',4),('44ba6a38-4f4b-415f-a0e0-b2b459c435ea','信息1','03e143d1-e667-4a1f-bd3d-618ab072a35b',NULL,'1',NULL,'信息1',1),('46caae30-b40e-4f8c-b8e0-7045fc52d5de','信息2','03e143d1-e667-4a1f-bd3d-618ab072a35b',NULL,'1',NULL,'信息2',2),('48c9e6d8-2ed8-468e-8a8e-54718498ab14','信息3','03e143d1-e667-4a1f-bd3d-618ab072a35b',NULL,'1',NULL,'信息3',3),('4c19b544-4829-472b-8d27-ce8e6a81b44c','信息4','03e143d1-e667-4a1f-bd3d-618ab072a35b',NULL,'1',NULL,'信息4',4),('56265cc0-a124-4805-a2a6-8a3d496a5fd6','Oracle','aed26c5e-17bc-45e6-9a02-3cd55b96aca4',NULL,'1',NULL,'Oracle',NULL),('5b4da21a-5cbf-47fc-abed-fd327d6a0249','Hbase','aed26c5e-17bc-45e6-9a02-3cd55b96aca4',NULL,'1',NULL,'Hbase',NULL),('6dba7076-5647-48ab-ba83-ecd619d66a12','Iowa','56265cc0-a124-4805-a2a6-8a3d496a5fd6',NULL,'1',NULL,'Iowa',NULL),('6f7af8c2-275a-4851-81b2-43348e6506de','Montana','56265cc0-a124-4805-a2a6-8a3d496a5fd6',NULL,'1',NULL,'Montana',NULL),('720fb0ef-20d5-4b99-8a75-b89b64df6104','Yamato','56265cc0-a124-4805-a2a6-8a3d496a5fd6',NULL,'1',NULL,'Yamato',NULL),('738ae384-acc5-440e-bacd-0cba6f7ac033','severodvinsk','5b4da21a-5cbf-47fc-abed-fd327d6a0249',NULL,NULL,NULL,'severodvinsk',NULL),('8b898c0f-2756-43e2-9d99-58e3f84317de','Ohio','5b4da21a-5cbf-47fc-abed-fd327d6a0249',NULL,NULL,NULL,'Ohio',NULL),('96b79a93-6434-43d3-b680-d60f6968a0cb','Delta','5b4da21a-5cbf-47fc-abed-fd327d6a0249',NULL,NULL,NULL,'Delta',NULL),('aed26c5e-17bc-45e6-9a02-3cd55b96aca4','数据源',NULL,NULL,'1',NULL,'数据源',2);
/*! 40000 the ALTER TABLE ` hub_sys_menu ` ENABLE KEYS */.
UNLOCK the TABLES;
/*! 40103 SET TIME_ZONE=@ OLD_TIME_ZONE */.

/*! 40101 SET SQL_MODE=@ OLD_SQL_MODE */.
/*! 40014 SET FOREIGN_KEY_CHECKS=@ OLD_FOREIGN_KEY_CHECKS */.
/*! 40014 SET UNIQUE_CHECKS=@ OLD_UNIQUE_CHECKS */.
/*! 40101 SET CHARACTER_SET_CLIENT=@ OLD_CHARACTER_SET_CLIENT */.
/*! 40101 SET CHARACTER_SET_RESULTS=@ OLD_CHARACTER_SET_RESULTS */.
/*! nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related