I have a table column where the same value can be repeated in across the several rows or maybe not. I want to return a count of all the values. A structure of my table is shown below
id | name | code
1 | xyz | 1.1
2 | 123 | 1.1
3 | foo | 2.1
3 | bob | 3.1
4 | roy | 2.1
I want to count the values in code
and so in this case the result should be 3
You want to count unique values of code
, as I understand the question. If so, SQL has count(distinct)
.
select count(distinct code)
from t;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.