Mysql-多表查询

记录下多表查询的大概流程


建表数据

CREATE TABLE `dept_p` (

  `DEPT_ID` varchar(40) NOT NULL,

  `PARENT_ID` varchar(40) DEFAULT NULL,

  `DEPT_NAME` varchar(50) DEFAULT NULL,

  `STATE` int(11) DEFAULT NULL,

  `CREATE_BY` varchar(40) DEFAULT NULL,

  `CREATE_DEPT` varchar(40) DEFAULT NULL,

  `CREATE_TIME` timestamp NULL DEFAULT CURRENT_TIMESTAMP,

  `UPDATE_BY` varchar(40) DEFAULT NULL,

  `UPDATE_TIME` timestamp NULL DEFAULT NULL,

  PRIMARY KEY (`DEPT_ID`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

insert into `dept_p`(`DEPT_ID`,`PARENT_ID`,`DEPT_NAME`,`STATE`,`CREATE_BY`,`CREATE_DEPT`,`CREATE_TIME`,`UPDATE_BY`,`UPDATE_TIME`) values ('100','---无上级---','汇通集团',1,NULL,NULL,'2018-09-25 07:41:53',NULL,'2018-09-25 09:25:17'),('100100','100','销售部',1,NULL,NULL,'2018-09-25 07:42:07',NULL,'2018-09-25 09:24:46'),('100200','100','货运部',0,NULL,NULL,'2018-09-25 07:42:23',NULL,'2018-09-25 09:03:37'),('100300','100','财务部',0,NULL,NULL,'2018-09-25 07:42:36',NULL,'2018-09-25 09:03:37'),('100400','100','仓库管理部',0,NULL,NULL,'2018-09-25 07:43:19',NULL,'2018-09-25 09:03:37'),('100500','100','法律事务部',0,NULL,NULL,'2018-09-25 07:43:58',NULL,'2018-09-25 09:03:37');


CREATE TABLE `user_info_p` (

  `USER_INFO_ID` varchar(40) NOT NULL,

  `NAME` varchar(20) DEFAULT NULL,

  `CARD_NO` varchar(20) DEFAULT NULL,

  `MANAGER_ID` varchar(40) DEFAULT NULL,

  `JOIN_DATE` timestamp NULL DEFAULT NULL,

  `SALARY` decimal(8,2) DEFAULT NULL,

  `BIRTHDAY` timestamp NULL DEFAULT NULL,

  `GENDER` char(1) DEFAULT NULL,

  `STATION` varchar(20) DEFAULT NULL,

  `TELEPHONE` varchar(100) DEFAULT NULL,

  `USER_LEVEL` char(1) DEFAULT NULL,

  `REMARK` varchar(600) DEFAULT NULL,

  `ORDER_NO` int(11) DEFAULT NULL,

  `CREATE_BY` varchar(40) DEFAULT NULL,

  `CREATE_DEPT` varchar(40) DEFAULT NULL,

  `CREATE_TIME` timestamp NULL DEFAULT CURRENT_TIMESTAMP,

  `UPDATE_BY` varchar(40) DEFAULT NULL,

  `UPDATE_TIME` timestamp NULL DEFAULT NULL,

  PRIMARY KEY (`USER_INFO_ID`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

insert into `user_info_p`(`USER_INFO_ID`,`NAME`,`CARD_NO`,`MANAGER_ID`,`JOIN_DATE`,`SALARY`,`BIRTHDAY`,`GENDER`,`STATION`,`TELEPHONE`,`USER_LEVEL`,`REMARK`,`ORDER_NO`,`CREATE_BY`,`CREATE_DEPT`,`CREATE_TIME`,`UPDATE_BY`,`UPDATE_TIME`) values ('091c8b02-d8da-4893-ad77-47605314d28e','213','123','1','2018-09-03 00:00:00','123.00','2018-08-27 00:00:00','男','123','123','4','123',213,NULL,NULL,'2018-09-27 16:08:30',NULL,NULL),('1','江流儿','110',NULL,'2018-09-25 13:56:17','10000.00','2018-09-25 13:56:25','男','项目经理','110','1','test',1,NULL,NULL,'2018-09-25 13:57:10',NULL,'2018-09-25 13:58:01'),('1c9d3627-9450-411d-8150-6ccf3999c7eb','123','213','1','2018-09-03 00:00:00','123.00','2018-08-27 00:00:00','男','123','213','2','123',213,NULL,NULL,'2018-09-26 10:08:29',NULL,NULL),('2','孙悟空','120','1','2018-09-25 13:57:37','10000.00','2018-09-25 13:57:45','男','程序员','120','1','test',2,NULL,NULL,'2018-09-25 13:57:28',NULL,'2018-09-25 13:58:10'),('207becea-403e-4785-8a2a-2c8fa8d81703','123','123','','2018-09-03 00:00:00','123123.00','2018-09-03 00:00:00','男','123','123','4','123',123,NULL,NULL,'2018-09-29 14:58:57',NULL,NULL),('3','沙悟净','130','1','2018-09-25 13:58:39','10000.00','2018-09-25 13:58:45','男','程序员','130','1','test',3,NULL,NULL,'2018-09-25 13:59:13',NULL,NULL),('38fa67b7-2b0c-49cb-9178-411e95e848e4','','','',NULL,NULL,NULL,NULL,'','','4','',NULL,NULL,NULL,'2018-09-26 17:00:42',NULL,NULL),('4','猪悟能','140','1','2018-09-25 13:59:39','10000.00','2018-09-25 13:59:44','男','程序员','140','1','test',4,NULL,NULL,'2018-09-25 14:00:03',NULL,NULL),('5','龙太子','150','1','2018-09-25 14:00:23','10000.00','2018-09-25 14:00:29','男','程序员','150','1','test',5,NULL,NULL,'2018-09-25 14:00:47',NULL,NULL),('9d4dc9c4-c36a-4005-a0d8-71c50a47c734','213','123','1c9d3627-9450-411d-8150-6ccf3999c7eb','2018-09-27 00:00:00','213.00','2018-09-04 00:00:00','男','123','213','4','213',213,NULL,NULL,'2018-09-27 16:07:23',NULL,NULL);

CREATE TABLE `user_p` (

  `USER_ID` varchar(40) NOT NULL,

  `DEPT_ID` varchar(40) DEFAULT NULL,

  `USERNAME` varchar(50) DEFAULT NULL,

  `PASSWORD` varchar(40) DEFAULT NULL,

  `STATE` int(11) DEFAULT NULL,

  `CREATE_BY` varchar(40) DEFAULT NULL,

  `CREATE_DEPT` varchar(40) DEFAULT NULL,

  `CREATE_TIME` timestamp NULL DEFAULT CURRENT_TIMESTAMP,

  `UPDATE_BY` varchar(40) DEFAULT NULL,

  `UPDATE_TIME` timestamp NULL DEFAULT NULL,

  PRIMARY KEY (`USER_ID`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

insert into `user_p`(`USER_ID`,`DEPT_ID`,`USERNAME`,`PASSWORD`,`STATE`,`CREATE_BY`,`CREATE_DEPT`,`CREATE_TIME`,`UPDATE_BY`,`UPDATE_TIME`) values ('091c8b02-d8da-4893-ad77-47605314d28e','100','222222','86482e5ce989c7ee63a8c46d1950abd1',1,NULL,NULL,'2018-09-27 16:08:30',NULL,NULL),('1','100100','唐僧','123',1,NULL,NULL,'2018-09-25 13:54:26',NULL,NULL),('1c9d3627-9450-411d-8150-6ccf3999c7eb','100','123','123',1,NULL,NULL,'2018-09-26 10:08:29',NULL,NULL),('2','100100','孙行者','123',1,NULL,NULL,'2018-09-25 13:54:39',NULL,'2018-09-25 13:54:59'),('207becea-403e-4785-8a2a-2c8fa8d81703','100','测试用户1','9b8b5b4202a78b7c21ef5d9007148be7',1,NULL,NULL,'2018-09-29 14:58:57',NULL,NULL),('3','100100','猪八戒','123',1,NULL,NULL,'2018-09-25 13:55:11',NULL,NULL),('38fa67b7-2b0c-49cb-9178-411e95e848e4','','','',NULL,NULL,NULL,'2018-09-26 17:00:42',NULL,NULL),('4','100100','沙僧','123',1,NULL,NULL,'2018-09-25 13:55:25',NULL,NULL),('5','100100','白龙马','123',1,NULL,NULL,'2018-09-25 13:55:46',NULL,NULL),('9d4dc9c4-c36a-4005-a0d8-71c50a47c734','100','123213','05d19ba139bef3acc4f37e9e8e5dedef',1,NULL,NULL,'2018-09-27 16:07:23',NULL,NULL);

你可能感兴趣的:(Mysql-多表查询)