Doubt to count records in a MySQL database query

-1

In a MySQL database, I have two columns of type varchar that brings me records in this format:

["165","184","192","209","242"]

One more example:

Each number in double quotation marks is a record, that is, it is the ID of some student.

I need a select that brings me how many IDs it has per column.

In the case of column curso1 , the result would be 8 .

Is this type of query possible?

    
asked by anonymous 25.09.2018 / 20:42

1 answer

0

I found a solution to your problem:

I made a test bank to which I added the records and did a test, here's what you need:

SELECT
  curso1,
  CASE WHEN COALESCE(curso1, '"')='"' THEN 0
  ELSE
    length(curso1)-length(replace(curso1, ',', ''))+
    (length(curso1)-length(replace(curso1, ' and ', ''))) DIV 5
    +1
  END
FROM
  suaTabela

change "yourTable" by the name of the table and make the query, I tried to perform this procedure via REGEX but it only returns 1 or 0.

The following illustrative image:

    
25.09.2018 / 21:47