How do I select and group by a portion of a string?

Posted by Russ Bradberry on Stack Overflow See other posts from Stack Overflow or by Russ Bradberry
Published on 2010-05-25T17:31:28Z Indexed on 2010/05/25 18:01 UTC
Read the original article Hit count: 206

Given I have data like the following, how can I select and group by portions of a string?

Version  Users
1.1.1    1
1.1.23   3
1.1.45   1
2.1.24   3
2.1.12   1
2.1.45   3
3.1.10   1
3.1.23   3

What I want is to sum up the users using version 1.1.x and 2.2.x and 3.3.x etc, but I'm not sure how I can group on a partial string in a select statement.

edit What the data should return like is this:

Version  Users
1.1.XX   5
2.1.XX   7
3.1.XX   4

There is an infinite variable number of versions, some are in this format (major, minor, build) some are just major, minor and some are just major, the only time I want to "roll up" the versions is when there is a build.

© Stack Overflow or respective owner

Related posts about sql

Related posts about postgresql