Reputation: 118
I want to get counted ids from count result in mysql
ID | version | count
========================
1 | 1.0 | 2
2 | 1.0 | 2
3 | 1.1 | 3
4 | 1.1 | 3
5 | 1.1 | 3
For example here i have returned counted version result,what if i want to get ids that are counted by count,simply like(list of ids that are counted),is it possible or any function available in mysql to do this?
I want a result like this
Count |counted_ids| version
========================
3 | 1 | 1.0
| 2 | 1.0
| 3 | 1.0
Upvotes: 0
Views: 299
Reputation: 1930
Use this statement on the table you posted in your question
SELECT `count`, GROUP_CONCAT(`ID`) FROM <your_table> GROUP BY `count`
For this Table:
ID | version | count
====================
0 | 1.0 | 2
1 | 1.0 | 2
2 | 1.0 | 2
3 | 1.1 | 3
4 | 1.1 | 3
5 | 1.1 | 3
It will give you something like this:
Count |GROUP_CONCAT(`ID`)|
==========================
3 | 3,4,5 |
2 | 0,1,2 |
Upvotes: 2
Reputation: 39
Please check following query,
select version,sum(count) count from table_name group by version
Upvotes: 2