请教各位牛人~
我有一张14W数据量的表 字段名分别是
id type location name 数据分别是
1 fruit china apple
2 animal china panada
3 wood china yew
4 fruit japa pear
5 animal japa spider
6 wood japa cherry
....................
.................
也就是说 id是自增长的 , type有fruit animal wood 等N多项, location是世界所有国家, 后面的name根据国家的不同也是都不一样的 。 有些没有某个type的国家在表里是没有记录的 , 比如说 韩国没有culture, 日本没有sport ,这样在表里该国家就会直接没有这个type 记录 ,而不是有记录字段却为空。我的问题就是该如何查找没有某个type的国家?
谢谢~
我有一张14W数据量的表 字段名分别是
id type location name 数据分别是
1 fruit china apple
2 animal china panada
3 wood china yew
4 fruit japa pear
5 animal japa spider
6 wood japa cherry
....................
.................
也就是说 id是自增长的 , type有fruit animal wood 等N多项, location是世界所有国家, 后面的name根据国家的不同也是都不一样的 。 有些没有某个type的国家在表里是没有记录的 , 比如说 韩国没有culture, 日本没有sport ,这样在表里该国家就会直接没有这个type 记录 ,而不是有记录字段却为空。我的问题就是该如何查找没有某个type的国家?
谢谢~
;with t1 as
(
--所有type
select distinct type from tab
)
,t2 as
(
--所有国家
select distinct location from tab
)
--列出所有国家缺少的type
select a.location,a.type
from (select location,type from t1,t2) a
left join (select location,type from tab group by location,type) b on a.type = b.type and a.location = b.location
where b.type is null
楼主,请记得结贴哦