【问题标题】:SQL Distinct on First Column OpenQuery第一列 OpenQuery 上的 SQL 不同
【发布时间】:2019-10-03 11:07:11
【问题描述】:

我在 SQL Server 2014 中使用 OpenQuery 从 Progress 中检索数据。

这是我的查询:

SELECT *
FROM OPENQUERY(PRG, 'SELECT "cde","dsc" FROM tblCodes') 

它会像这样检索数据:

cde     dsc
===     =====
one     test
one     another
one     value
two     goes
two     here
two     also
three   example

但是,我需要让结果看起来像这样:

cde     dsc
===     =====
one     test
two     goes
three   example

如何在OpenQuery 中执行此操作?

【问题讨论】:

    标签: sql-server tsql progress-4gl openquery progress-db


    【解决方案1】:

    在您的公开查询中,您的查询应该如下所示,我建议您将 cde 列作为数字 ID:

     WITH CTE AS (select cde,dsc,
        row_number() over(
                            partition by cde
                            order by cde
                        ) as rn
    
    from tblCodes 
    )
    select cde,dsc from CTE 
    where rn =1
    

    在这里检查执行:sqlfiddle

    【讨论】:

    • 这行得通。仅供参考:cde 是一个字符串字段,而不是数字
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多