How to count the number of comma-separated items in Mysql?

Asked

Viewed 875 times

1

I have a field in a table with data separated by comma: condicao_pagamento: 20,25,35,45,50.

How do I count the number of comma-separated items using Mysql only?

1 answer

0


Check if this is what you want:

LENGTH(fooCommaDelimColumn) - LENGTH(REPLACE(fooCommaDelimColumn, ',', ''))

link

  • I had found this code a few days ago, it works almost perfectly. However, I thought this was not the correct way to count the number of items separated by comma. Do you know if there are any commands like FIND_IN_SET or IN, specific to count items separated by comma, without the need to perform this "calculation"?

  • I don’t, and from the research I’ve done I couldn’t find any function that could do that...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.