在SQL Server中尝试使用内部联接获取数据时,列获取错误数据

在SQL Server中尝试使用内部联接获取数据时,列获取错误数据,sql,sql-server-2012,Sql,Sql Server 2012,我的数据库中有两个表 交易表 M_Trans Table 我已经这样设置了查询 select distinct inv.transId as Order ID, sfc.nofaktur as Faktur, inv.amount as PPn, inv.salesId from Transaction inv inner join M_Trans sfc on sfc.invoice=inv.invoice where ( DATEPART(yy, inv.d

我的数据库中有两个表

  • 交易表

  • M_Trans Table

  • 我已经这样设置了查询

    select distinct inv.transId as Order ID,
    sfc.nofaktur as Faktur, 
    inv.amount as PPn,
    inv.salesId
    
    from Transaction inv
        inner join M_Trans sfc on sfc.invoice=inv.invoice
    where (
             DATEPART(yy, inv.date) = '2018'
             AND DATEPART(mm, inv.date) = '2'
          )         
    
          order by sfc.nofaktur asc
    
    但它不能满足我的需要,我的超越结果如下:`

    查询结果如下: (salesId中的数据不正确)

    如何修复查询以便获取所需数据?


    谢谢

    MySQL不是Microsoft SQL server。您到底使用了什么?
    内部连接M_Trans efa在sfc.invoice=inv.invoice
    -什么是
    sfc
    ?此查询如何工作?表中没有一个别名是
    sfc
    ,但您正在使用它
    sfc.invoice
    很抱歉,我已经更新了问题。我使用的是基于您提供的示例数据的SQL Server(没有
    inv.date
    ,因此我没有使用
    WHERE
    子句),您的查询工作正常。