Input Table: City
+-----------+
| Name |
+-----------+
| AAA |
+-----------+
| AAA |
+-----------+
| BBB |
+-----------+
| CCC |
+-----------+
The table City has one column Name
. I want output that will return the difference between total numbers of city name and distinct number of city name.
In case of this table the result would be 1.
Use COUNT
and DISTINCT
COUNT
.
SELECT COUNT(name)-COUNT(DISTINCT name) AS nameDifference
FROM city
Output:
nameDifference
1
Try this
SELECT COUNT(Name)-COUNT(DISTINCT Name) AS NewName
FROM city
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