Skip to content

Redshift SQL REGEXP_REPLACE function

I have a value which is duplicated from source (can’t do anything about that). I have read some examples here https://docs.aws.amazon.com/redshift/latest/dg/REGEXP_REPLACE.html Example value: 2.859,00€…

Postgres: Split column values & transpose

I have a table like this: And I want to convert it to this: I have tried splitting the column based on ; but the product_id count varies based on the category_id. Is there anyway I can achieve this? Answer You can use PostgreSQL’s array manipulation functions: string_to_array does exactly what it says —…

MySQL find first row base on multiple conditions

Suppose exists a table as follows: For each id, i want to keep the row with maximum B, if B equals, then keep the row with maximum C. So the final result is, how to realize it by SQL? Answer Maximum tasks can be solved with NOT EXISTS. You only want rows for which not exists a row with the

Parse JSON like VARCHAR Column in Snowflake

I have a VARCHAR column called TAG within a SQL database with the data looking like the example below. Example: Since it is not a JSON column, I am having difficulty parsing through the column to get the postScore value. I have tried to convert this from a VARCHAR to Variant datatype so that I can do somethin…