I have to display the countries that are big by area or big by population but not both and Show name, population and area. Basically it's a XOR operation if i am not wrong.
A country is big if it has an area of more than 3 million sq km or it has a population of more than 250 million.
I have tried this
SELECT name, population, area
FROM world
WHERE (area > 30000000 | population > 25000000) &
(area < 30000000 & population < 25000000)
I am trying this on sqlzoo.net - SELECT_from_WORLD_Tutorial: Q.No-8. Please select the SQL Engine to SQLSERVER.
MySQL XOR operator checks two operands (or expressions) and returns TRUE if one or the other but not both is TRUE.
SQL AND OR NOT and XOR statement can be used with WHERE clause to list a set of records with matching combination of a database table.
XOR is a bitwise operator, and it stands for "exclusive or." It performs logical operation. If input bits are the same, then the output will be false(0) else true(1).
Bitwise operators perform bit manipulations between two expressions of any of the data types of the integer data type category. Bitwise operators convert two integer values to binary bits, perform the AND, OR, or NOT operation on each bit, producing a result.
You can implement a XOR like this - don't forget that the question will require you to use <= to correctly use the XOR operator:
SELECT name
, population
, area
FROM world
WHERE (area > 3000000 AND population <= 250000000)
OR (area <= 3000000 AND population > 250000000)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With