0

So I have a column in mysql db that has values such as '34343|dollar' and '2343|dollar'. I wish to get all the column values, then remove the '|dollar' string and get the average of the numbers. How can I achieve this?

3

1 Answer 1

0

Something like this:

select AVG(CONVERT(REPLACE(col,'|dollar',''), SIGNED INTEGER)) from my_table;

'col' is your column that has the values as you mentioned.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, after that how do I get the result to echo it? seems that it is an object and not a string. thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.