0

I've a big table in my mysql db. In this table one column contain the metadata of all the content I've. the value is quite long and I need to extract the duration of all the video. this is an extract of the field:

{"progress":100,"id":"10","duration":4285,"audio":[],"status":"published" ..... 

I need to take care of the value after the "duration":

The value can start to 1 and be up to 10000.

How can I do?

1 Answer 1

1

Try with something like this:

SELECT SUBSTRING(
 substr, 
 LOCATE(':', substr) + 1,
 LOCATE(',', substr) - LOCATE(':', substr) -1) as duration FROM 
(SELECT SUBSTRING(column, LOCATE('"duration":', column)) substr
 FROM log_debug WHERE column REGEXP '\"duration\":')  as foo;

The inner select gets a substring that starts at 'duration' and spans to the end of the whole string, for all rows that have the duration field (add more conditions in the where if you want).

The outer select then gets a substring starting after the first ':' and ending before the ','

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

3 Comments

Hi Mamuso, thank you for your reply. Trying to run it (I have to add another where clause because of the huge quantity of rows) doesn't return nothing. then, once retrieved the value is it possible to sum it? thank you very much
Please update your question with the query you are making to see what may be wrong. To sum the durations, you only have to do SELECT SUM( SUBSTRING ... ) as total_duration FROM ...
Hi, I did it and worked like a charm. thank you very much.

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.