wangqifanjob 于 2016.04.14 17:00 提问

mysql 递归算法，统计数量

CREATE TABLE Org(
org_code varchar(80) PRIMARY KEY,
org_name varchar(80),
parent_org_code varchar(80)
)engine=innodb charset=UTF8;

INSERT INTO Org values('24500000000','陕西省税务局','');

INSERT INTO Org values('24501000000','西安市税务局','24500000000');
INSERT INTO Org values('24502000000','咸阳市税务局','24500000000');
INSERT INTO Org values('24503000000','宝鸡市税务局','24500000000');

INSERT INTO Org values('24501010000','西安市碑林区税务局','24501000000');
INSERT INTO Org values('24501020000','西安市雁塔区税务局','24501000000');

INSERT INTO Org values('24502010000','咸阳市杨凌区税务局','24502000000');
INSERT INTO Org values('24502050000','咸阳市乾县税务局','24502000000');

INSERT INTO Org values('24503010000','宝鸡市岐山县税务局','24503000000');
INSERT INTO Org values('24503090000','宝鸡市金台区税务局','24503000000');

INSERT INTO Org values('24501012100','西安市碑林区一股','24501010000');
INSERT INTO Org values('24501012200','西安市碑林区二股','24501010000');

CREATE TABLE Project(
prod_id tinyint,
prod_org_code varchar(80)
)engine=innodb charset=UTF8;
INSERT INTO Project values
(1,'24501012200'),
(2,'24503000000'),
(3,'24501020000'),
(4,'24502050000'),
(5,'24503000000'),
(6,'24503090000'),
(7,'24503000000'),
(8,'24501020000'),
(9,'24502010000'),
(10,'24501012100')

1个回答

xxmvzeetbb   2016.10.08 01:41

Org values('24502000000','咸阳市税务局','24500000000');
INSERT INTO Org values('24503000000','宝鸡市税务局','24500000000');
INSERT INTO Org values('24501010000','西安市碑林区税务局','24501000000');
INSERT INTO Org values('24501020000','西安市雁塔区税务局','24501000000');
INSERT INTO Org values('24502010000','咸阳市杨凌区税务局','24502000000');
INSERT INTO Org values('24502050000','咸阳市乾县税务局','24502000000');
INSERT INTO Org values('24503010000','宝鸡市岐山县税务局','24503000000');
INSERT INTO Org values('24503090000','宝鸡市金台区税务局','24503000000');
INSERT INTO Org values('24501012100','西安市碑林区一股','24501010000');
INSERT INTO Org values('24501012200','西安市碑林区二股','24501010000');
CREATE TABLE Project(
prod_id tinyint,
prod_org_code varchar(80)