sql-server - 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:
Highly appreciate the assistance. I'm using SQL Server 2017.
解决方案
不再需要。这个问题可以关闭。没有找到解决方案,更改了源系统以适应需要的内容。
推荐阅读
- java - Apache Cayenne“类未与 Cayenne 映射”
- sql - 仅保留审计表中每个对象的最后 5 行
- amcharts - Amchart V4 将所有现有的 amchart 一起导出到一个页面中
- python - 是否可以使用 aiohttp 运行多个 gunicorn 工作者?
- sql - 从可变长度的变量集中动态生成字符串
- php - 仅向管理员显示数组中的项目
- testing - Mocha / Chia 测试在通过/失败测试之前不等待方法链完成
- php - Nest API,单击按钮,运行更改数据的 PHP 函数,然后重新加载数据
- pandas - 围绕 Seaborn FacetGrid 轴绘制框
- python - Python3 中的 MATLAB fwind1