SQL query to read Array values of a Order Value column | Community
Skip to main content
DineshRkumar
October 28, 2024
Solved

SQL query to read Array values of a Order Value column

  • October 28, 2024
  • 1 reply
  • 628 views

Hi Team,  

In Data feed raw data, Order_value column has multiple values inside the Array.  Can you please help me with Query to sum up array. 

 

for instance:  

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by MandyGeorge

There might be an easier way to do this, but it's been a while since I've had to do SQL regularly.

If you want to sum up the values in an array, you need to split out the values of that array, you can do that with the "SPLIT" function, which will put each value on it's own line using a delimiter. But you also have the brackets at the start/end of the array, so you need to get rid of those, I did that with the "REPLACE" function. Just replaced the bracket with an empty value.

 

split(replace(replace(rev_values, "[", ""), "]", ""), ",")

 

 

Once all of the values are on their own row, you can do your normal aggregations to sum.

 

1 reply

MandyGeorge
Community Advisor and Adobe Champion
MandyGeorgeCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
October 31, 2024

There might be an easier way to do this, but it's been a while since I've had to do SQL regularly.

If you want to sum up the values in an array, you need to split out the values of that array, you can do that with the "SPLIT" function, which will put each value on it's own line using a delimiter. But you also have the brackets at the start/end of the array, so you need to get rid of those, I did that with the "REPLACE" function. Just replaced the bracket with an empty value.

 

split(replace(replace(rev_values, "[", ""), "]", ""), ",")

 

 

Once all of the values are on their own row, you can do your normal aggregations to sum.