Mysql中表student_table(id,name,birth,sex),插入如下记录: (‘1001’ , ” , ‘2000-01-01’ , ‘男’); (‘1002’ , null , ‘2000-12-21’ , ‘男’); (‘1003’ , NULL , ‘2000-05-20’ , ‘男’); (‘1004’ , ‘张三’ , ‘2000-08-06’ , ‘男’); (‘1005’ , ‘李四’ , ‘2001-12-01’ , ‘女’); (‘1006’ , ‘张三’ , ‘2001-12-02’ , ‘女’); 执行  select t1.name ,t2.name from   (select * from student_table where sex = ‘女’) t1   left join   (select * from student_table where sex = ‘男’) t2   on t1.name = t2.name  where t2.name is null   union  select t1.name ,t2.name from   (select * from student_table where sex = ‘女’) t1   right join   (select * from student_table where sex = ‘男’) t2   on t1.name = t2.name  where t1.name is null;-笔试面试资料

这是qklbishe.com第19243 篇笔试面试资料
提供答案分析,通过本文《Mysql中表student_table(id,name,birth,sex),插入如下记录: (‘1001’ , ” , ‘2000-01-01’ , ‘男’);
(‘1002’ , null , ‘2000-12-21’ , ‘男’);
(‘1003’ , NULL , ‘2000-05-20’ , ‘男’);
(‘1004’ , ‘张三’ , ‘2000-08-06’ , ‘男’);
(‘1005’ , ‘李四’ , ‘2001-12-01’ , ‘女’);
(‘1006’ , ‘张三’ , ‘2001-12-02’ , ‘女’); 执行
 select t1.name ,t2.name from   (select * from student_table where sex = ‘女’) t1 
 left join 
 (select * from student_table where sex = ‘男’) t2 
 on t1.name = t2.name  where t2.name is null   union  select t1.name ,t2.name from 
 (select * from student_table where sex = ‘女’) t1 
 right join 
 (select * from student_table where sex = ‘男’) t2 
 on t1.name = t2.name  where t1.name is null;-笔试面试资料》可以理解其中的代码原理,这是一篇很好的求职学习资料
本站提供程序员计算机面试经验学习,笔试经验,包括字节跳动/头条,腾讯,阿里,美团,滴滴出行,网易,百度,京东,小米,华为,微软等互联网大厂真题学习背诵。

答案:

Mysql中表student_table(id,name,birth,sex),插入如下记录:
(‘1001’ , ” , ‘2000-01-01’ , ‘男’);
(‘1002’ , null , ‘2000-12-21’ , ‘男’);
(‘1003’ , NULL , ‘2000-05-20’ , ‘男’);
(‘1004’ , ‘张三’ , ‘2000-08-06’ , ‘男’);
(‘1005’ , ‘李四’ , ‘2001-12-01’ , ‘女’);
(‘1006’ , ‘张三’ , ‘2001-12-02’ , ‘女’);

执行

 select t1.name ,t2.name from 

 (select * from student_table where sex = ‘女’) t1 
 left join 
 (select * from student_table where sex = ‘男’) t2 

 on t1.name = t2.name  where t2.name is null 
 union

 select t1.name ,t2.name from 
 (select * from student_table where sex = ‘女’) t1 
 right join 
 (select * from student_table where sex = ‘男’) t2 

 on t1.name = t2.name  where t1.name is null;
Mysql中表student_table(id,name,birth,sex),插入如下记录:       ('1001' , '' , '2000-01-01' , '男');   ('1002' , null , '2000-12-21' , '男');   ('1003' , NULL , '2000-05-20' , '男');   ('1004' , '张三' , '2000-08-06' , '男');   ('1005' , '李四' , '2001-12-01' , '女');         ('1006' , '张三' , '2001-12-02' , '女');   执行        select t1.name ,t2.name from    (select * from student_table where sex = '女') t1     left join     (select * from student_table where sex = '男') t2       on t1.name = t2.name  where t2.name is null      union   select t1.name ,t2.name from     (select * from student_table where sex = '女') t1     right join     (select * from student_table where sex = '男') t2       on t1.name = t2.name  where t1.name is null; 区块链毕设学生836322360号

该题可能要问的是“查询结果有几条行数据”

如果问的是查询结果有几条数据的话,结果又有不同:

  1. 如果使用Oracle是2条,因为Oracle数据库中空字符串和null是相等的,而且用union连接时会进行唯一性过滤——该题2条数据。
  2. 如果是mySql是3条,因为MySql数据库中空字符和null不相等,所以在进行union连接时的唯一性过滤后,会比Oracle多一条——该题3条数据。
今天 18:24:44 回复(0)

文章部分来自互联网,侵权联系删除
www.qklbishe.com

区块链毕设网(www.qklbishe.com)全网最靠谱的原创区块链毕设代做网站
部分资料来自网络,侵权联系删除!
资源收费仅为搬运整理打赏费用,用户自愿支付 !
qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台 » Mysql中表student_table(id,name,birth,sex),插入如下记录: (‘1001’ , ” , ‘2000-01-01’ , ‘男’); (‘1002’ , null , ‘2000-12-21’ , ‘男’); (‘1003’ , NULL , ‘2000-05-20’ , ‘男’); (‘1004’ , ‘张三’ , ‘2000-08-06’ , ‘男’); (‘1005’ , ‘李四’ , ‘2001-12-01’ , ‘女’); (‘1006’ , ‘张三’ , ‘2001-12-02’ , ‘女’); 执行  select t1.name ,t2.name from   (select * from student_table where sex = ‘女’) t1   left join   (select * from student_table where sex = ‘男’) t2   on t1.name = t2.name  where t2.name is null   union  select t1.name ,t2.name from   (select * from student_table where sex = ‘女’) t1   right join   (select * from student_table where sex = ‘男’) t2   on t1.name = t2.name  where t1.name is null;-笔试面试资料

提供最优质的资源集合

立即查看 了解详情