+-------------+------------+
| Field | Type |
+-------------+------------+
| ID | INTEGER |
| CITY | VARCHAR(21)|
| STATE | VARCHAR(2) |
| LAT_N | NUMERIC |
| LONG_W | NUMERIC |
+-------------+------------
Find the difference between the total number of CITY entries in the table and the number of distinct CITY entries in the table.
If I use the minus keyword then its not working but when i use the actual minus sign it works like
SELECT (COUNT(CITY)- COUNT(DISTINCT CITY))
FROM STATION;
why is that?
SELECT COUNT(CITY) FROM STATION
MINUS
SELECT COUNT(DISTINCT CITY) FROM STATION;
minusis a similar operator asunion- it combines multiple sets of rows to a new set of rows. It is Oracle's non-standard version of theEXCEPToperator.EXCEPT(orMINUS) returns all rows from the first set that are not contained in the second.Assuming the tables contains 10 rows and 5 different cities, then
So the query
SELECT COUNT(CITY) FROM STATIONreturns the following result set:and
SELECT COUNT(DISTINCT CITY) FROM STATIONreturnsAs
MINUSreturns the rows from the first set that are not contained in the second, the result of theMINUSoperator is only the first row.This also works with multiple rows and columns. Assume you have two queries.
The first one returns this
and the second one returns
combining both with
EXCEPT(orMINUS) will returnBecause those are the rows from the first set, that are not present in the second.
-subtracts one number value from another so it only works on columns in the SELECT list, not on complete sets of rows.