group by and count values from text field

2762 views mysql
5

my table looks like:

ID, TEXT_FIELD
--
1  "Text, me RR"
2  "Another, me AA"
3  "New, me CC"
4  "Like, me RR"

I would like to group and count all "me RR", "me AA", "me CC" and in the best case I would like to finally get:

RR 2
AA 1
CC 1

Any idea please how?

answered question

2 Answers

0

You can use GROUP BY and RIGHT() to do it

SELECT right(t.TEXT_FIELD,2),count(t.id) 
   FROM yourtable t GROUP BY t.TEXT_FIELD

posted this
3

select text_of_interest , count(text_of_interest)
from your_table
group by substring(text_field, length(text_field) - 2, 3) as text_of_interest

posted this

Have an answer?

JD

Please login first before posting an answer.