2012-09-27 184 views
0

是由a.MEMB進行分組的一種方式嗎?我研究了它並找到了一些解決方法,但似乎無法使其發揮作用。我不想對其他coolumns中的whats感興趣,但我確實需要在結果中顯示它們。按選擇列表中的一列進行分組-SQL

;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 
) 
+1

哪個數據庫? –

+2

@RajeshChamarthi:聲明終止字符在聲明的開始和'nolock'似乎表明SQL Server的事實 –

回答

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 
+0

感謝重新工作後,我有一點與這個解決方案一起工作謝謝。保持獲得專欄,但總體而言,但不想這樣做。 – LewSim

相關問題