MySQL起步小白在sqlzoo上遇到一个扣脑袋的题,在此分享:
Exclusive OR (XOR). Show the countries that are big by area (more than 3 million) or big by population (more than 250 million) but not both. Show name, population and area.
Australia has a big area but a small population, it should be included.
Indonesia has a big population but a small area, it should be included.
China has a big population and big area, it should be excluded.
United Kingdom has a small population and a small area, it should be excluded.
中文:
异或(XOR)。显示按面积大(超过300万)或按人口大(超过2.5亿)大的国家,但不能同时显示这两个国家。显示姓名,人口和面积。
澳大利亚有一个很大的地区,但人口少,应列入。
印度尼西亚人口众多,但面积很小,应该包括在内。
中国人口众多,面积很大,应该排除在外。
英国人口少,面积小,应该排除在外。
数据表:
就一直在扣这个异或怎么写,用^符号为什么不对,为什么用xor也不对?直到现在还没搞懂。。。
所以我换了个思路:
select name, population, area from world where
((area > 3000000) and (population < 250000000))
or (area < 3000000) and (population > 250000000);
这样就完美解决问题。