编辑代码

create database test; 
use test;
CREATE TABLE student_table (
	id varchar(255),
	name varchar(255),
	birth varchar(255),
	sex varchar(255)
);

INSERT INTO student_table VALUES ('1004', '张三', '2000-08-06', '男');
INSERT INTO student_table VALUES ('1005', 'NULL', '2001-12-01', '女');
INSERT INTO student_table VALUES ('1006', '张三', '2000-08-06', '女');
INSERT INTO student_table VALUES ('1007', '王五', '2001-12-01', '男');
INSERT INTO student_table VALUES ('1008', '李四', NULL, '女');
INSERT INTO student_table VALUES ('1009', '李四', NULL, '男');
INSERT INTO student_table VALUES ('1010', '李四', '2001-12-01', '女');

select t1.*,t2.*
from
    (select * from student_table where sex = '男') t1
    right join
    (select * from student_table where sex = '女') t2
    on t1.birth = t2.birth and t1.name = t2.name;