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 But no Positive Result。

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

任何人都可以展示获取准确数据的方法吗

4

1 回答 1

0

我猜您想对数据进行分组并汇总金额:

SELECT tba.[Order Date], SUM(tba.Amount), SUM(te.[Gross Salary])
FROM tblBudget tba 
JOIN tblEar te on tba.EventId = te.Event_ID
WHERE tba.EventId = 14
GROUP BY tba.[Order Date]
于 2012-04-13T12:20:30.877 回答