首页 > 解决方案 > Achieve the same result from this postgresql query in SQL Server 2017

问题描述

I have the following query that runs in postgresql-9.6, I need to achieve the same output on a SQL Server DB.

Here is the query, I've replaced all fields from my DB with the string values that would come from them anyway (DB Fields are: "primary_key_fields", "primary_key_values", "table_name", "min_sequence"):

SELECT 
UNNEST(STRING_TO_ARRAY(demo.primary_key_fields, ',')) AS primary_key_fields,    
UNNEST(STRING_TO_ARRAY(demo.primary_key_values, ',')) AS primary_key_values, 
table_name, 
min_sequence, 
ROW_NUMBER() OVER(partition by demo.primary_key_fields) AS rn

FROM (
    SELECT
    'Name,surname,age,location,id' AS primary_key_fields,
    'Nash,Marley,27,South Africa,121' AS primary_key_values,
    'person' AS table_name, 
    '1' AS min_sequence

    UNION ALL
    SELECT
    'Name,surname,age,location,id' AS primary_key_fields,   
    'Paul,Scott,25,South America,999' AS primary_key_values, 
    'person' AS table_name, 
    '1' AS min_sequence
    ) demo

I'm expecting the following output:

Expected Output

Highly appreciate the assistance. I'm using SQL Server 2017.

标签: sql-servertsqlsplitsql-server-2017

解决方案


不再需要。这个问题可以关闭。没有找到解决方案,更改了源系统以适应需要的内容。


推荐阅读