Skip to content
Advertisement

How to select rows with uniq value of column and to calculate count?

I have table like this for example: I need to select each uniq column by ver and to calculate how much is total of rows by each uniq ver column I think each total to add into the new column

table:
id  name  ver 
1   one   5
2   two   5
3   three 6
4   four  6
5   five  8

SELECT, something like this

id  ver total
1   5   2
2   6   2
4   8   1

Advertisement

Answer

Query

select MIN(id) as id, ver, COUNT(ver) as total
from your_table_name
group by ver;
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement