0
我有2個表,如下所示加盟條件檢索不需要答案
select Event_ID,[Gross Salary] from tblEar where Event_ID=14
結果:
Event_ID Gross Salary
14 56128
14 51984
14 42028
和:
select EventId, [Order Date],Amount from tblBudget where EventId=14
結果:
EventId Order Date Amount
14 10/10/2011 20000
14 10/10/2011 20000
14 20/03/2012 2500
14 02/04/2012 -50000
如果我在這兩個表上寫一個連接表達來獲取它是檢索重複的記錄。我用Distinct但沒有正面結果。
select DISTINCT tba.[Order Date],ISNULL(tba.Amount,0),ISNULL(te.[Gross Salary],0) from tblBudget tba
join
tblEar te on tba.EventId=te.Event_ID where tba.EventId=14
我得到了以下答案:
Order Date (No column name) (No column name)
2011-10-10 20000.00 42028.00
2011-10-10 20000.00 51984.00
2011-10-10 20000.00 56128.00
2012-03-20 2500.00 42028.00
2012-03-20 2500.00 51984.00
2012-03-20 2500.00 56128.00
2012-04-02 -50000.00 42028.00
2012-04-02 -50000.00 51984.00
2012-04-02 -50000.00 56128.00
任何一個可以告訴你要組數據的方式來獲得Accuarate數據
我已經格式化了您的問題,以便查詢和結果可以被讀取(我還切換了前兩個查詢的順序到結果,因爲結果集似乎更好地匹配查詢)。但是你沒有告訴我們你期待的結果*。 – 2012-04-13 12:16:19