SELECT
*
FROM `t_test`
WHERE ( `pid` IN ( SELECT id FROM `t_test` WHERE `pid` = "1" AND type = 1 ) AND type = 2 ) OR ( `pid` = "1" AND type = 2 )
the structure of the data table is as follows:
?
:
INSERT INTO agent.t_test (id, pid, type) VALUES ("1", "0", "0");
INSERT INTO agent.t_test (id, pid, type) VALUES ("2", "1", "1");
INSERT INTO agent.t_test (id, pid, type) VALUES ("3", "2", "2");
INSERT INTO agent.t_test (id, pid, type) VALUES ("4", "1", "2");
INSERT INTO agent.t_test (id, pid, type) VALUES ("5", "1", "1");
INSERT INTO agent.t_test (id, pid, type) VALUES ("6", "5", "2");
INSERT INTO agent.t_test (id, pid, type) VALUES ("7", "2", "2");
INSERT INTO agent.t_test (id, pid, type) VALUES ("8", "5", "1");
CREATE TABLE t_test (id int(11) NOT NULL AUTO_INCREMENT,pid int(11) NOT NULL,type tinyint(4) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4;
:
