Hive&SqlServerql:inner join on条件中如果两边都是空值的情况下,关联结果中会把数据给过滤掉。
今天遇到的一个大坑,话不多少,看sql和下边的查询结果:
1 --问题:恰好把buildingid is null的记录给过滤掉 2 create table tommyduan_gridcell_group_all_test(gridid nvarchar(32),buildingid nvarchar(32),floor nvarchar(32)); 3 insert into tommyduan_gridcell_group_all_test(gridid,buildingid,floor)values('g1',null,1); 4 insert into tommyduan_gridcell_group_all_test(gridid,buildingid,floor)values('g2','b1',1); 5 insert into tommyduan_gridcell_group_all_test(gridid,buildingid,floor)values('g2','b2',1); 6 insert into tommyduan_gridcell_group_all_test(gridid,buildingid,floor)values('g3','b2',1); 7 insert into tommyduan_gridcell_group_all_test(gridid,buildingid,floor)values('g3','b2',2); 8 insert into tommyduan_gridcell_group_all_test(gridid,buildingid,floor)values('g3','b2',4); 9 10 11 create table tommyduan_fingerlib(gridid nvarchar(32),buildingid nvarchar(32),floor nvarchar(32)); 12 insert into tommyduan_fingerlib(gridid,buildingid,floor)values('g1',null,1); 13 insert into tommyduan_fingerlib(gridid,buildingid,floor)values('g2','b1',1); 14 insert into tommyduan_fingerlib(gridid,buildingid,floor)values('g2','b2',1); 15 insert into tommyduan_fingerlib(gridid,buildingid,floor)values('g3','b2',1); 16 insert into tommyduan_fingerlib(gridid,buildingid,floor)values('g3','b2',2); 17 insert into tommyduan_fingerlib(gridid,buildingid,floor)values('g3','b2',4); 18 19 20 select * from tommyduan_gridcell_group_all_test t10 21 inner join tommyduan_fingerlib t11 22 on t10.gridid=t11.gridid and t10.buildingid=t11.buildingid and t10.floor=t11.floor
查询结果:
解决方案:
1 select * from 2 ( 3 select gridid,buildingid,floor,gridid+(case when buildingid is null then 'd_null' else buildingid end)+floor as tkey 4 from tommyduan_gridcell_group_all_test 5 ) t10 6 inner join 7 ( 8 select gridid,buildingid,floor,gridid+(case when buildingid is null then 'd_null' else buildingid end)+floor as tkey 9 from tommyduan_fingerlib 10 ) t11 11 on t10.tkey=t11.tkey
查询结果:
left outer join时的查询结果是:
1 select * from tommyduan_gridcell_group_all_test t10 2 left outer join tommyduan_fingerlib t11 3 on t10.gridid=t11.gridid and t10.buildingid=t11.buildingid and t10.floor=t11.floor
基础才是编程人员应该深入研究的问题,比如:
1)List/Set/Map内部组成原理|区别
2)mysql索引存储结构&如何调优/b-tree特点、计算复杂度及影响复杂度的因素。。。
3)JVM运行组成与原理及调优
4)Java类加载器运行原理
5)Java中GC过程原理|使用的回收算法原理
6)Redis中hash一致性实现及与hash其他区别
7)Java多线程、线程池开发、管理Lock与Synchroined区别
8)Spring IOC/AOP 原理;加载过程的。。。
【+加关注】。