简体   繁体   English

SQL SELECT中的结果太多

[英]Too many results in SQL SELECT

Here is my SQL Statement... 这是我的SQL语句...

SELECT     
    dbo.PPMASTER.Per_or_Bus, 
    dbo.PPMASTER.Assessment_Date, 
    dbo.PPBUSMST.Assessment_Number, 
    dbo.PPBUSMST.Year
FROM dbo.PPBUSMST INNER JOIN dbo.PPMASTER 
                  ON dbo.PPBUSMST.Assessment_Number = dbo.PPMASTER.Assessment_Number
WHERE (dbo.PPBUSMST.Assessment_Number = @Assessment)

The problem is that I get duplicate results stemming from the Assessment_Date . 问题是我从Assessment_Date得到重复的结果。 Each Assessment_Date should only have one result per Year. 每个Assessment_Date每年仅应有一个结果。 Any ideas? 有任何想法吗?

Here is some of the results sample data... 这是一些结果样本数据...

**B 1996-05-29 00:00:00 9005450 1996**
B   1996-05-29 00:00:00 9005450 1997
B   1996-05-29 00:00:00 9005450 1998
B   1996-05-29 00:00:00 9005450 1999
B   1996-05-29 00:00:00 9005450 2000
B   1996-05-29 00:00:00 9005450 2001
B   1996-05-29 00:00:00 9005450 2002
B   1997-05-29 00:00:00 9005450 1996
**B 1997-05-29 00:00:00 9005450 1997**
B   1997-05-29 00:00:00 9005450 1998
B   1997-05-29 00:00:00 9005450 1999
B   1997-05-29 00:00:00 9005450 2000
B   1997-05-29 00:00:00 9005450 2001
B   1997-05-29 00:00:00 9005450 2002
B   1998-04-27 00:00:00 9005450 1996
B   1998-04-27 00:00:00 9005450 1997
**B 1998-04-27 00:00:00 9005450 1998**
B   1998-04-27 00:00:00 9005450 1999
B   1998-04-27 00:00:00 9005450 2000
B   1998-04-27 00:00:00 9005450 2001
B   1998-04-27 00:00:00 9005450 2002

The ones I have **'d are the results I actually want to achieve 我**想要得到的就是我实际上想要实现的结果

Looking at what you've marked as wanting to achieve, it implies that your join conditions are incomplete. 查看您标记为要达到的目标,这意味着您的join条件不完整。 The rows you want are not only the ones where PPBUSMST.Assessment_Number = PPMASTER.Assessment_Number , but also where YEAR(PPMASTER.Assessment_Date) = PPBUSMST.[Year] . 所需的行不仅是PPBUSMST.Assessment_Number = PPMASTER.Assessment_Number ,而且是YEAR(PPMASTER.Assessment_Date) = PPBUSMST.[Year]

Adding that to your join conditions should resolve the problem. 将其添加到您的join条件中可以解决该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM