Mysql中表student_table(id,name,birth,sex),插入如下记录:
('1003' , '' , '2000-01-01' , '男');
('1004' , '张三' , '2000-08-06' , '男');
('1005' , NULL , '2001-12-01' , '女');
('1006' , '张三' , '2000-08-06' , '女');
('1007' , ‘王五’ , '2001-12-01' , '男');
('1008' , '李四' , NULL, '女');
('1009' , '李四' , NULL, '男');
('1010' , '李四' , '2001-12-01', '女');
执行
select t1.*,t2.*
from (
select * from student_table where sex = '男' ) t1
inner join
(select * from student_table where sex = '女')t2
on t1.birth = t2.birth and t1.name = t2.name ;
的结果行数是()?
A、4
B、3
C、2
D、1
答案:D
解析:
题目中【inner join ... on t1.birth = t2.birth and t1.name = t2.name ; 】inner join意思是左右表中的birth、name都不为NULL时才会匹配上,结果中不含有一个字段为NULL或两个字段都为NULL的记录,结果只有‘张三’一条记录。所以选D.
查询结果如下图: