0

他们是按 a.MEMB 分组的一种方式吗?我已经对其进行了研究,并找到了一些解决方法,但似乎无法让它发挥作用。我对其他冷却器中的内容不感兴趣,但我确实需要在结果中显示它们。

 ;with main as (SELECT a.MEMB
   , ta.DRAW
   , ta.foc
   , a.ENTRY
  , tc.DESCRIP

   FROM a with (nolock)
          inner join  tal      
   inner join  ta      
         inner join tc        
  WHERE a.ENTRY between @start and @end
   and a.TRAN != 0
   and tc.TRANN=a.TRANN
   and tc.TRANT=a.TRANT  
)
4

1 回答 1

1

您可以使用ROW_NUMBER()对数据进行分区。但是,您的查询目前无法工作,因为您缺少连接

;with main as 
(SELECT a.MEMB, ta.DRAW, ta.foc, a.ENTRY, tc.DESCRIP,
        row_number() over (partition by a.MEMB order by a.Memb) rn
 FROM a with (nolock) 
 inner join  tal on ...
 inner join  ta  on ...     
 inner join tc     on    tc.TRANN=a.TRANN 
     and tc.TRANT=a.TRANT   
  WHERE a.ENTRY between @start and @end 
   and a.TRAN != 0 
) 
    select * from main where rn = 1
于 2012-09-27T12:58:17.513 回答